Bad behaviour when inserting unspecified variable length datatypes - Mailing list pgsql-hackers

From Dave Blasby
Subject Bad behaviour when inserting unspecified variable length datatypes
Date
Msg-id 3B8FE657.300C7B03@refractions.net
Whole thread Raw
Responses Re: Bad behaviour when inserting unspecified variable length datatypes
List pgsql-hackers
It took me a while to figure out what was going on, but I think I've
figured it out.

Lets say you have your own variable length datatype called
'MY_DATATYPE'.

CREATE TABLE test_table (myint integer, mydata MY_DATATYPE);
INSERT INTO test_table VALUES (1);

At this point, I'd expect there to be one row in test table. The myint
column will have the value one, and the mydata column will have the
value NULL.

This doesnt appear to be the case.  It seems that the mydata column will
have a structure that looks like a '-'::TEXT structure (ie. the first 4
bytes are an int representing 5, and the 5th byte is the ASCII '-').

This is really bad because a "SELECT * FROM test_table" will send this
weird structure to MY_DATATYPE's OUTPUT function.  Since this weird
structure isn't really a MY_DATATYPE structure, it causes problems.

This happens even if you explictly set MY_DATATYPE's DEFAULT to NULL.

dave


pgsql-hackers by date:

Previous
From: Hannu Krosing
Date:
Subject: Re: Escaping strings for inclusion into SQL queries
Next
From: Martin Weinberg
Date:
Subject: Why "ERROR: dtoi4: integer out of range" on pg_dump