Thread: text vs. varchar
Is there any difference between "text" and "varchar" data types? (Not varchar(n), just varchar.) I can't see a differentfrom the manual page, but I'm wondering about index usage or something similarly subtle.
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 differentfrom 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
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 differentfrom 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 ===========================================================
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 differentfrom 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
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 differentfrom 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.
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 differentfrom 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