Unix Technical Forum

Disadvantages to using "text"

This is a discussion on Disadvantages to using "text" within the pgsql Novice forums, part of the PostgreSQL category; --> Are there any reasons for not using the "text" type whenever a variable length string field is needed? Are ...


Go Back   Unix Technical Forum > Database Server Software > PostgreSQL > pgsql Novice

Register FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 05-07-2008, 06:21 PM
Don Mies
 
Posts: n/a
Default Disadvantages to using "text"

Are there any reasons for not using the "text" type whenever a variable
length string field is needed? Are there penalties in disk usage,
memory usage or performance?



What are the differences between declaring something "varchar" or
"varchar(n)" or "text"? (I realize that the middle one has an upper
limit while the others do not.)





Don






Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 05-07-2008, 06:21 PM
=?UTF-8?Q?Rodrigo_E._De_Le=C3=B3n_Plicet?=
 
Posts: n/a
Default Re: Disadvantages to using "text"

On Wed, May 7, 2008 at 10:52 AM, Don Mies (NIM)
<dmies@networksinmotion.com> wrote:
> Are there any reasons for not using the "text" type whenever a variable
> length string field is needed? Are there penalties in disk usage, memory
> usage or performance?
>
> What are the differences between declaring something "varchar" or
> "varchar(n)" or "text"? (I realize that the middle one has an upper limit
> while the others do not.)


Reading The Fine Manual reveals all that is asked:
http://www.postgresql.org/docs/8.3/s...character.html

--
Sent via pgsql-novice mailing list (pgsql-novice@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-novice

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 05-07-2008, 06:21 PM
Richard Broersma
 
Posts: n/a
Default Re: Disadvantages to using "text"

On Wed, May 7, 2008 at 8:52 AM, Don Mies (NIM)
<dmies@networksinmotion.com> wrote:
> Are there any reasons for not using the "text" type whenever a variable
> length string field is needed? Are there penalties in disk usage, memory
> usage or performance?


Some client programs don't know how to deal with this and the
unconstrained VARCHAR datatype. Especially where they are used as
primary/foreign key or as collumns used in grouping aggregates. For
example MS-Access and Crystal reports maps the text data type as a
memo field which has limitations.


> What are the differences between declaring something "varchar" or
> "varchar(n)" or "text"? (I realize that the middle one has an upper limit
> while the others do not.)


Practically, VARCHAR = TEXT. Client programs like VARCHAR(N) as long
as it can map its constained text datatype to it.


--
Regards,
Richard Broersma Jr.

Visit the Los Angles PostgreSQL Users Group (LAPUG)
http://pugs.postgresql.org/lapug

--
Sent via pgsql-novice mailing list (pgsql-novice@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-novice

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 05-07-2008, 06:21 PM
Tom Lane
 
Posts: n/a
Default Re: Disadvantages to using "text"

"Don Mies (NIM)" <dmies@networksinmotion.com> writes:
> Are there any reasons for not using the "text" type whenever a variable
> length string field is needed? Are there penalties in disk usage,
> memory usage or performance?


No, no, and no. The only good reason I've heard of to avoid text is
that there are some "database independent" client-side tools that
don't really understand it, and if you're using one of those it's
a problem.

regards, tom lane

--
Sent via pgsql-novice mailing list (pgsql-novice@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-novice

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 05-07-2008, 06:21 PM
Aurynn Shaw
 
Posts: n/a
Default Re: Disadvantages to using "text"

> Are there any reasons for not using the “text” type whenever a variable
> length string field is needed? Are there penalties in disk usage,
> memory usage or performance?
>
>
>
> What are the differences between declaring something “varchar” or
> “varchar(n)” or “text”? (I realize that the middle one has an upper
> limit while the others do not.)


Actually, no, there's no reason to use varchar over text, unless you are
wanting to explicitly limit the input length of your data.

Internally, Postgres treats a VARCHAR(n) as a TEXT with a CHECK
constraint applied to it, so VARCHAR is going to be slightly slower to use.

Hope that helps,
Aurynn.

--
Aurynn Shaw

The PostgreSQL Company - Command Prompt, Inc. 1.503.667.4564 ext 103
PostgreSQL Replication, Consulting, Custom Development, 24x7 support

ashaw@commandprompt.com

--
Sent via pgsql-novice mailing list (pgsql-novice@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-novice

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #6 (permalink)  
Old 05-07-2008, 06:21 PM
Bruce Hyatt
 
Posts: n/a
Default Re: Disadvantages to using "text"

--- Aurynn Shaw <ashaw@commandprompt.com> wrote:
> Internally, Postgres treats a VARCHAR(n) as a TEXT with a
> CHECK
> constraint applied to it, so VARCHAR is going to be slightly
> slower to use.


VARCHAR is slower too? There's no check on VARCHAR, is there?

Bruce


__________________________________________________ __________________________________
Be a better friend, newshound, and
know-it-all with Yahoo! Mobile. Try it now. http://mobile.yahoo.com/;_ylt=Ahu06i...Dypao8Wcj9tAcJ

--
Sent via pgsql-novice mailing list (pgsql-novice@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-novice

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #7 (permalink)  
Old 05-07-2008, 06:21 PM
Tom Lane
 
Posts: n/a
Default Re: Disadvantages to using "text"

Bruce Hyatt <brucejhyatt@yahoo.com> writes:
> VARCHAR is slower too? There's no check on VARCHAR, is there?


Well, all the textual operators/functions are actually declared to take
and return type TEXT, so when you are working with VARCHAR columns the
expressions have no-op cast nodes in them ("RelabelType" nodes), even
if it's an unconstrained-length VARCHAR. I'm not sure whether the
execution cost of these would be measurable in real applications, but
it's not zero. A bigger problem is that sometimes the planner gets
confused by the RelabelTypes and fails to find as good a plan as it
finds for a pure-TEXT query. Now if you run into that kind of problem
it's a bug and should be reported, but nonetheless you'll get stuck with
bad plans until it's fixed ...

regards, tom lane

--
Sent via pgsql-novice mailing list (pgsql-novice@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-novice

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #8 (permalink)  
Old 05-07-2008, 06:21 PM
Frank Bax
 
Posts: n/a
Default Re: Disadvantages to using "text"

Aurynn Shaw wrote:
> Internally, Postgres treats a VARCHAR(n) as a TEXT with a CHECK
> constraint applied to it, so VARCHAR is going to be slightly slower to use.



Don't you mean VARCHAR(n) will be slightly slower on UPDATES.

--
Sent via pgsql-novice mailing list (pgsql-novice@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-novice

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #9 (permalink)  
Old 05-07-2008, 06:21 PM
Greg Cocks
 
Posts: n/a
Default Re: Disadvantages to using "text"

One disadvantage is that if you are using MS Access as a front-end via
ODBC / linked tables, you can not do joins on fields set as text (in
queries, etc)


-----Original Message-----
From: Frank Bax [mailto:fbax@sympatico.ca]
Sent: Wednesday, May 07, 2008 10:55 AM
To: PostgreSQL List - Novice
Subject: Re: [NOVICE] Disadvantages to using "text"

Aurynn Shaw wrote:
> Internally, Postgres treats a VARCHAR(n) as a TEXT with a CHECK
> constraint applied to it, so VARCHAR is going to be slightly slower to

use.


Don't you mean VARCHAR(n) will be slightly slower on UPDATES.

--
Sent via pgsql-novice mailing list (pgsql-novice@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-novice

--
Sent via pgsql-novice mailing list (pgsql-novice@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-novice

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #10 (permalink)  
Old 05-10-2008, 02:06 PM
Obe, Regina
 
Posts: n/a
Default Re: Disadvantages to using "text"

The other disadvantage I have noticed is that you can't override operator behavior of text but you can for varchar.

So I have been able to override the case sensitivity of varchar fields (which is annoying when working with MS Access etc) simply by changing the way LIKE, = > etc. are handled for varchar. Since text is defined in pg_catalog, it doesn't seem possible to override it or at least haven't had any success with that. Maybe I am missing something.

Thanks,
Regina


________________________________

From: pgsql-novice-owner@postgresql.org on behalf of Greg Cocks
Sent: Wed 5/7/2008 1:48 PM
To: PostgreSQL List - Novice
Subject: Re: [NOVICE] Disadvantages to using "text"



One disadvantage is that if youare using MS Access as a front-end via
ODBC / linked tables, you can not do joins on fields set as text (in
queries, etc)


-----Original Message-----
From: Frank Bax [mailto:fbax@sympatico.ca]
Sent: Wednesday, May 07, 2008 10:55 AM
To: PostgreSQL List - Novice
Subject: Re: [NOVICE] Disadvantages to using "text"

Aurynn Shaw wrote:

> Internally, Postgres treats a VARCHAR(n) as a TEXT with a CHECK
> constraint applied to it, so VARCHAR is going to be slightly slower to

use.


Don't you mean VARCHAR(n) willbe slightly slower on UPDATES.

--
Sent via pgsql-novice mailing list (pgsql-novice@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-novice

--
Sent via pgsql-novice mailing list (pgsql-novice@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-novice




-----------------------------------------
The substance of this message, including any attachments, may be
confidential, legally privileged and/or exempt from disclosure
pursuant to Massachusetts law. It is intended
solelyfor the addressee. If you received this in error, please
contact the sender and delete the material from any computer.

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 01:37 PM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com