Re: PK/FK impacts using text data type - Mailing list pgsql-admin

From Tom Lane
Subject Re: PK/FK impacts using text data type
Date
Msg-id 23199.1420917650@sss.pgh.pa.us
Whole thread Raw
In response to Re: PK/FK impacts using text data type  (Albe Laurenz <laurenz.albe@wien.gv.at>)
List pgsql-admin
Albe Laurenz <laurenz.albe@wien.gv.at> writes:
> The only useful thing about varchar is that it imposes a length constraint on a database field.

> Values used for indexing have a length limit, so if you change an indexed column to text
> somebody could try to insert values that will cause errors because the limit has been exceeded.

I'm not particularly buying that argument.  If you insert an overlength
field value, you will get an error either way; it's just spelled
differently.  Also, using varchar(N) isn't a particularly efficient way to
guard the btree length limit, because N is measured in characters but the
btree length limit is in bytes.  You'd have to use a very conservatively
small N to be absolutely sure you don't get a btree error, and that would
result in throwing some errors that actually weren't necessary at all.

> Also you application code cannot rely on a certain size limit any more.

This is a valid argument, though again only to the extent that you need a
size limit measured in characters not bytes.

            regards, tom lane


pgsql-admin by date:

Previous
From: Albe Laurenz
Date:
Subject: Re: PK/FK impacts using text data type
Next
From: David G Johnston
Date:
Subject: Re: PK/FK impacts using text data type