Hi, I wanted to do some transformation on an inet value from an SPI-using function. The inet Datum passed from SPI_getbinval() to the values array in heap_form_tuple() obviously gives good data to the frontend. When I use DatumGetInetP() on the Datum, the structure passed to me is corrupt:
zozo=# select * from inet_test() as (id integer, i1 inet, i2 inet); NOTICE: i1 family=CORRUPTED NOTICE: i1 family=CORRUPTED NOTICE: i1 family=CORRUPTED id | i1 | i2 ----+-------------+--------------- 1 | 192.168.0.1 | 192.168.0.101 2 | 192.168.0.2 | 192.168.0.102 3 | 192.168.0.3 | 192.168.0.103 (3 rows) I looked at utils/inet.h and DatumGetInetP() uses PG_DETOAST_DATUM_PACKED(). fmgr.h warns about PG_DETOAST_DATUM_PACKED() that it may give you an unaligned pointer. Indeed, using PG_DETOAST_DATUM() instead of the _PACKED variant on the Datum give me a well formed inet structure: zozo=# select * from inet_test() as (id integer, i1 inet, i2 inet); NOTICE: i1 family=AF_INET NOTICE: i1 netmask=32 bits NOTICE: i1 address=192.168.0.1 NOTICE: i1 family=AF_INET NOTICE: i1 netmask=32 bits NOTICE: i1 address=192.168.0.2 NOTICE: i1 family=AF_INET NOTICE: i1 netmask=32 bits NOTICE: i1 address=192.168.0.3 id | i1 | i2 ----+-------------+--------------- 1 | 192.168.0.1 | 192.168.0.101 2 | 192.168.0.2 | 192.168.0.102 3 | 192.168.0.3 | 192.168.0.103 (3 rows) System is Fedora 16/x86_64, PostgreSQL 9.1.1 as provided by the OS. The same error occurs on PostgreSQL 9.0.4 on another system which is also Linux/x86_64 Example code is attached, the tables used by the code are: create table t1 (id serial primary key, i1 inet); create table t2 (id serial primary key, id2 integer references t1(id), i2 inet); insert into t1 (i1) values ('192.168.0.1'); insert into t1 (i1) values ('192.168.0.2'); insert into t1 (i1) values ('192.168.0.3'); insert into t2 (id2, i2) values (1, '192.168.0.101'); insert into t2 (id2, i2) values (2, '192.168.0.102'); insert into t2 (id2, i2) values (3, '192.168.0.103'); Best regards, Zoltán Böszörményi -- ---------------------------------- Zoltán Böszörményi Cybertec Schönig & Schönig GmbH Gröhrmühlgasse 26 A-2700 Wiener Neustadt, Austria Web: http://www.postgresql-support.de http://www.postgresql.at/
inet-test.tgz
Description: application/compressed-tar
-- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers