Re: PG 7.2 varchar change - Mailing list pgsql-admin

From Christopher Browne
Subject Re: PG 7.2 varchar change
Date
Msg-id m3pt5v3btk.fsf@wolfe.cbbrowne.com
Whole thread Raw
In response to Re: distibuted database for postgresql  ("Goulet, Dick" <DGoulet@vicr.com>)
List pgsql-admin
Quoth slane@moyergroup.com (slane):
> Hello all:
>
> I am upgrading a web application from postgres 7.1.2 to 7.4.3 (too long in
> coming to that point, I know).
>
> I have sifted through the history files and identified a restricted number
> of changes that potentially impact the app, a few of which I don¹t
> understand.
>
> Here¹s the currently most alarming, a change that is recorded for 7.2:
>
> CHAR(), VARCHAR() now reject strings that are too long (Peter E)

Consider this example:

tutorial=# create table test_string (f1 varchar, f2 varchar(10));
CREATE TABLE
tutorial=# insert into test_string (f1, f2) values ('abc', 'def');
INSERT 2623360 1
tutorial=# insert into test_string (f1, f2) values ('abcdefghijklmnopqrstuvwxyz', 'def');
INSERT 2623361 1
tutorial=# insert into test_string (f1, f2) values ('abcdefghijklmnopqrstuvwxyz', 'abcdefghiasdfasdfa');
ERROR:  value too long for type character varying(10)

If no maximum length is specified, PostgreSQL is free to stick a
goodly amount of data in the field.

But supposing you decide that a particular column is VARCHAR(10),
trying to stuff more than 10 characters into it will fail, as you see
above.

Doing similar with char:

tutorial=# create table test_chars (f1 char, f2 char(10));
CREATE TABLE
tutorial=# insert into test_chars (f1, f2) values ('abc', 'def');
ERROR:  value too long for type character(1)

Does that illustrate what's going on?  I hope so...
--
let name="cbbrowne" and tld="cbbrowne.com" in name ^ "@" ^ tld;;
http://www3.sympatico.ca/cbbrowne/spreadsheets.html
"Fashion is a form of ugliness so intolerable that we have to alter it
every six months."  -- Oscar Wilde

pgsql-admin by date:

Previous
From: Tom Lane
Date:
Subject: Re: PG 7.2 varchar change
Next
From: MPaule Torre
Date:
Subject: redhat Ent3 et postegresql v7.4.3