Bad behaviour when inserting unspecified variable length datatypes

From: Dave Blasby <dblasby(at)refractions(dot)net>
To: pgsql-hackers(at)postgresql(dot)org
Subject: Bad behaviour when inserting unspecified variable length datatypes
Date: 2001-08-31 19:32:39
Message-ID: 3B8FE657.300C7B03@refractions.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Martin Weinberg 2001-08-31 20:04:31 Why "ERROR: dtoi4: integer out of range" on pg_dump
Previous Message Barry Lind 2001-08-31 17:03:04 Re: Escaping strings for inclusion into SQL queries