Re: PK/FK impacts using text data type

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Albe Laurenz <laurenz(dot)albe(at)wien(dot)gv(dot)at>
Cc: "Ferrell, Denise CTR NSWCDD, Z11 *EXTERN*" <denise(dot)ferrell(dot)ctr(at)navy(dot)mil>, "pgsql-admin(at)postgresql(dot)org" <pgsql-admin(at)postgresql(dot)org>
Subject: Re: PK/FK impacts using text data type
Date: 2015-01-10 19:20:50
Message-ID: 23199.1420917650@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-admin

Albe Laurenz <laurenz(dot)albe(at)wien(dot)gv(dot)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

In response to

Browse pgsql-admin by date

  From Date Subject
Next Message David G Johnston 2015-01-10 19:25:48 Re: PK/FK impacts using text data type
Previous Message Albe Laurenz 2015-01-10 19:14:09 Re: PK/FK impacts using text data type