From: Gavan Schneider <pg-gts@snkmail.com>
To: pgsql-general@postgresql.org
Subject: Re: question about varchar
Date: Wed, 19 Dec 2012 13:39:48 +1100
Message-ID: <3384-1355884792-626106@sneakemail.com> (raw)
In-Reply-To: <201212182315.qBINFgMU011248@news.hub.org>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-general>
On Tuesday, December 18, 2012 at 10:15, Rui Li wrote:
/*
** text 'cleaned' to remove message digest cruft
** apologies for any errors
*/
>In postgresql, we can create column as varchar(n)=94 where n is the
>sizeof the char, or we can just define column as varchar=94
>rli=3D# CREATE TABLE test (v1 varchar(100), v2 varchar);
>CREATE TABLE
>rli=3D# \d test
>Table "public.test"
>Column | Type | Modifiers
>--------+------------------------+-----------
>v1 | character varying(100) |
>v2 | character varying |
>
>so my question is: why should we even declare character varying(n) in
>postgresql when there's an easier options to declaring character
>varying (without n) is there any performance different between it? or
>some other reason we should use varchar(n) instead of just varchar?
>
>thanks for any help
>
The short answer seems to be: just use text, e.g.,
CREATE TABLE test (v1 text, v2 text);
and, only go to varchar(n) if there is a very special need.
Lots of good reasons to not use char(n) if you cannot guarantee
to fill the field every time (otherwise those right filled blank
padding characters will just cause problems).
There is no speed performance difference between them, but lots
of design advantages in favour of text (it's much more 'future proof').
These ideas are much better explained, and tested here:
<http://www.depesz.com/2010/03/02/charx-vs-varcharx-vs-varchar-vs-text/;
Regards
Gavan Schneider
--
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-general@postgresql.org
Cc: pg-gts@snkmail.com
Subject: Re: question about varchar
In-Reply-To: <3384-1355884792-626106@sneakemail.com>
References: <201212182315.qBINFgMU011248@news.hub.org> <3384-1355884792-626106@sneakemail.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
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