pg.ddx.io pgsql-admin@postgresql.org mailing list archive
help / color / mirror / Atom feedPK/FK impacts using text data type
4+ messages / 4 participants
[nested] [flat]
* PK/FK impacts using text data type
@ 2015-01-09 16:22 Ferrell, Denise CTR NSWCDD, Z11 <denise.ferrell.ctr@navy.mil>
0 siblings, 1 reply; 4+ messages in thread
From: Ferrell, Denise CTR NSWCDD, Z11 @ 2015-01-09 16:22 UTC (permalink / raw)
To: pgsql-admin
Good Morning,
Using Linux/PostgreSQL 9.3.
We have been discussing whether or not to change all of our varchar (character varying) data types to text for ease of use in procedures/functions/triggers...
Are there any impacts on keys by using text data type vs. character varying or character varying(n)?
Thank you in advance,
Denise Ferrell
--
Sent via pgsql-admin mailing list (pgsql-admin@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-admin
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: PK/FK impacts using text data type
@ 2015-01-10 19:14 Albe Laurenz <laurenz.albe@wien.gv.at>
parent: Ferrell, Denise CTR NSWCDD, Z11 <denise.ferrell.ctr@navy.mil>
0 siblings, 2 replies; 4+ messages in thread
From: Albe Laurenz @ 2015-01-10 19:14 UTC (permalink / raw)
To: Ferrell, Denise CTR NSWCDD, Z11 *EXTERN* <denise.ferrell.ctr@navy.mil>; pgsql-admin
Denise Ferrell wrote:
> We have been discussing whether or not to change all of our varchar (character varying)
> data types to text for ease of use in procedures/functions/triggers...
>
> Are there any impacts on keys by using text data type vs. character varying or character varying(n)?
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.
Also you application code cannot rely on a certain size limit any more.
If you are ok with that, go ahead and use text.
Yours,
Laurenz Albe
--
Sent via pgsql-admin mailing list (pgsql-admin@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-admin
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: PK/FK impacts using text data type
@ 2015-01-10 19:20 Tom Lane <tgl@sss.pgh.pa.us>
parent: Albe Laurenz <laurenz.albe@wien.gv.at>
1 sibling, 0 replies; 4+ messages in thread
From: Tom Lane @ 2015-01-10 19:20 UTC (permalink / raw)
To: Albe Laurenz <laurenz.albe@wien.gv.at>; +Cc: Ferrell, Denise CTR NSWCDD, Z11 *EXTERN* <denise.ferrell.ctr@navy.mil>; 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
--
Sent via pgsql-admin mailing list (pgsql-admin@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-admin
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: PK/FK impacts using text data type
@ 2015-01-10 19:25 David G Johnston <david.g.johnston@gmail.com>
parent: Albe Laurenz <laurenz.albe@wien.gv.at>
1 sibling, 0 replies; 4+ messages in thread
From: David G Johnston @ 2015-01-10 19:25 UTC (permalink / raw)
To: pgsql-admin
Albe Laurenz *EXTERN* wrote
> Denise Ferrell wrote:
>> We have been discussing whether or not to change all of our varchar
>> (character varying)
>> data types to text for ease of use in procedures/functions/triggers...
>>
>> Are there any impacts on keys by using text data type vs. character
>> varying or character varying(n)?
>
> 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.
>
> Also you application code cannot rely on a certain size limit any more.
>
> If you are ok with that, go ahead and use text.
>
> Yours,
> Laurenz Albe
Appropriate check constraints can handle the majority of the needed cases.
In theory, domains would be helpful here too but I'm not totally conversant
on them at the moment.
David J.
--
View this message in context: http://postgresql.nabble.com/PK-FK-impacts-using-text-data-type-tp5833407p5833533.html
Sent from the PostgreSQL - admin mailing list archive at Nabble.com.
--
Sent via pgsql-admin mailing list (pgsql-admin@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-admin
^ permalink raw reply [nested|flat] 4+ messages in thread
end of thread, other threads:[~2015-01-10 19:25 UTC | newest]
Thread overview: 4+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2015-01-09 16:22 PK/FK impacts using text data type Ferrell, Denise CTR NSWCDD, Z11 <denise.ferrell.ctr@navy.mil>
2015-01-10 19:14 ` Albe Laurenz <laurenz.albe@wien.gv.at>
2015-01-10 19:20 ` Tom Lane <tgl@sss.pgh.pa.us>
2015-01-10 19:25 ` David G Johnston <david.g.johnston@gmail.com>
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox