varchar() troubles - Mailing list pgsql-hackers

From Thomas G. Lockhart
Subject varchar() troubles
Date
Msg-id 34BA2DF8.84496BD1@alumni.caltech.edu
Whole thread Raw
Responses Re: varchar() troubles
List pgsql-hackers
I've been seeing trouble with varchar() columns for a little while, and
since it is still there with a fresh install of the development tree
it's time to report it:

postgres=> create table t (v varchar(80),i int);
CREATE
postgres=> insert into t values ('hi',1);
INSERT 18122 1
postgres=> select * from t;
v |i
--+-
hi|0
(1 row)

As you can see, the varchar() column apparently trashes the subsequent
column. I ran across it trying to verify the tutorial examples for the
documentation. If the varchar() is the last column in the table, the
problem does not crop up, at least in the simplest case:

postgres=> create table t2 (i int, v varchar(80));
CREATE
postgres=> insert into t2 values (2,'hi');
INSERT 18133 1
postgres=> select * from t2;
i|v
-+--
2|hi
(1 row)

Also, I believe that if the varchar() field is substantially shorter the
problem does not manifest itself:

postgres=> create table t4 (v varchar(4), i int);
CREATE
postgres=> insert into t4 values ('hi',4);
INSERT 18156 1
postgres=> select * from t4;
v |i
--+-
hi|4
(1 row)

but varchar(10) still shows the problem:

postgres=> create table t3 (v varchar(10), i int);
CREATE
postgres=> insert into t3 values ('hi',3);
INSERT 18145 1
postgres=> select * from t3;
v |i
--+-
hi|0
(1 row)

This is from the development source as of around 1998-01-12 14:30 GMT

                                                                    -
Tom


pgsql-hackers by date:

Previous
From: Andrew Martin
Date:
Subject: Compression (was Re: [HACKERS] varchar/char size)
Next
From: Andrew Martin
Date:
Subject: Re: [HACKERS] PSQL man page patch