text vs. varchar

Started by Benover 15 years ago5 messagesgeneral
Jump to latest
#1Ben
bench@silentmedia.com

Is there any difference between "text" and "varchar" data types? (Not varchar(n), just varchar.) I can't see a different from the manual page, but I'm wondering about index usage or something similarly subtle.

#2Joshua D. Drake
jd@commandprompt.com
In reply to: Ben (#1)
Re: text vs. varchar

On Wed, 2010-07-21 at 08:58 -0700, Ben Chobot wrote:

Is there any difference between "text" and "varchar" data types? (Not varchar(n), just varchar.) I can't see a different from the manual page, but I'm wondering about index usage or something similarly subtle.

They are the same thing. So is varchar(n) it just has a length
constraint.

JD

--
PostgreSQL.org Major Contributor
Command Prompt, Inc: http://www.commandprompt.com/ - 509.416.6579
Consulting, Training, Support, Custom Development, Engineering

#3Peter C. Lai
peter@simons-rock.edu
In reply to: Joshua D. Drake (#2)
Re: text vs. varchar

varchar allows you to define an explicit length of the field, text does not.
varchar with a length specified (varchar(n)) is sql92 compliant while
varchar() and text are pgsql extensions.

On 2010-07-21 08:58:54AM -0700, Ben Chobot wrote:

Is there any difference between "text" and "varchar" data types? (Not varchar(n), just varchar.) I can't see a different from the manual page, but I'm wondering about index usage or something similarly subtle.
--
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general

--
===========================================================
Peter C. Lai | Bard College at Simon's Rock
Systems Administrator | 84 Alford Rd.
Information Technology Svcs. | Gt. Barrington, MA 01230 USA
peter AT simons-rock.edu | (413) 528-7428
===========================================================

#4Thom Brown
thombrown@gmail.com
In reply to: Ben (#1)
Re: text vs. varchar

On 21 July 2010 16:58, Ben Chobot <bench@silentmedia.com> wrote:

Is there any difference between "text" and "varchar" data types? (Not varchar(n), just varchar.) I can't see a different from the manual page, but I'm wondering about index usage or something similarly subtle.
--

Here's what Tom Lane had to say on the matter when I asked previously:

"There is some potential overhead from using varchar instead of text
because of the extra dummy cast nodes that are likely to be present in
your query expressions (since all the native functions are declared to
take/return text, not varchar). In most cases I'd think you'd be
hard-put to measure any difference though."

Thom

#5Ben
bench@silentmedia.com
In reply to: Thom Brown (#4)
Re: text vs. varchar

On Jul 21, 2010, at 9:05 AM, Thom Brown wrote:

On 21 July 2010 16:58, Ben Chobot <bench@silentmedia.com> wrote:

Is there any difference between "text" and "varchar" data types? (Not varchar(n), just varchar.) I can't see a different from the manual page, but I'm wondering about index usage or something similarly subtle.
--

Here's what Tom Lane had to say on the matter when I asked previously:

"There is some potential overhead from using varchar instead of text
because of the extra dummy cast nodes that are likely to be present in
your query expressions (since all the native functions are declared to
take/return text, not varchar). In most cases I'd think you'd be
hard-put to measure any difference though."

Thanks, this is precisely what I was looking for.