Simple 'type' question

Started by Tim Barnardabout 24 years ago3 messagesgeneral
Jump to latest
#1Tim Barnard
tbarnard@povn.com

When creating a table with a primary key that can contain any varying
sequence of alphanumeric characters, is it best to use the 'text' type or
the 'varchar' type? Or will the implicit index that's created on the primary
key work equally well with either type? Any suggestions would be much
appreciated.

Tim Barnard
S.E. Mgr
Hartford Communications Corporation

#2Tom Lane
tgl@sss.pgh.pa.us
In reply to: Tim Barnard (#1)
Re: Simple 'type' question

"Tim Barnard" <tbarnard@povn.com> writes:

When creating a table with a primary key that can contain any varying
sequence of alphanumeric characters, is it best to use the 'text' type or
the 'varchar' type?

If you want a specific upper limit on the string length, use varchar.
If that's not needed, use text. The only difference in performance
AFAIK is the extra function call per insert/update for the routine that
enforces the varchar limit.

regards, tom lane

#3Tim Barnard
tbarnard@povn.com
In reply to: Tim Barnard (#1)
Re: Simple 'type' question

Thanks Tom.

Tim Barnard
S.E. Mgr
Hartford Communications Corporation

----- Original Message -----
From: "Tom Lane" <tgl@sss.pgh.pa.us>
To: "Tim Barnard" <tbarnard@povn.com>
Cc: <pgsql-general@postgresql.org>
Sent: Thursday, January 24, 2002 3:51 PM
Subject: Re: [GENERAL] Simple 'type' question

"Tim Barnard" <tbarnard@povn.com> writes:

When creating a table with a primary key that can contain any varying
sequence of alphanumeric characters, is it best to use the 'text' type

or

Show quoted text

the 'varchar' type?

If you want a specific upper limit on the string length, use varchar.
If that's not needed, use text. The only difference in performance
AFAIK is the extra function call per insert/update for the routine that
enforces the varchar limit.

regards, tom lane