Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1Tl9Zo-0008Ol-6t for pgsql-general@arkaria.postgresql.org; Wed, 19 Dec 2012 02:40:08 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.72) (envelope-from ) id 1Tl9Zn-0001BZ-Af for pgsql-general@arkaria.postgresql.org; Wed, 19 Dec 2012 02:40:07 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1Tl9Zm-0001AX-2U for pgsql-general@postgresql.org; Wed, 19 Dec 2012 02:40:06 +0000 Received: from sneak2.sneakemail.com ([38.113.6.65]) by magus.postgresql.org with smtp (Exim 4.72) (envelope-from ) id 1Tl9Zh-0007o6-UC for pgsql-general@postgresql.org; Wed, 19 Dec 2012 02:40:04 +0000 Received: (qmail 26142 invoked from network); 19 Dec 2012 02:39:54 -0000 Received: from unknown (HELO localhost.localdomain) (192.168.0.1) by sneak2.sneakemail.com with SMTP; 19 Dec 2012 02:39:54 -0000 Received: from 61.9.168.143 by mail.sneakemail.com with SMTP; 19 Dec 2012 02:39:54 -0000 Received: (sneakemail censored 3384-1355884792-626106 #2); 19 Dec 2012 02:39:54 -0000 Received: (sneakemail censored 3384-1355884792-626106 #1); 19 Dec 2012 02:39:54 -0000 Date: Wed, 19 Dec 2012 13:39:48 +1100 From: Gavan Schneider Subject: Re: question about varchar To: pgsql-general@postgresql.org In-Reply-To: <201212182315.qBINFgMU011248@news.hub.org> Message-ID: <3384-1355884792-626106@sneakemail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: quoted-printable X-Mailer: Perl5 Mail::Internet v X-Pg-Spam-Score: -2.6 (--) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-general Precedence: bulk Sender: pgsql-general-owner@postgresql.org 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)=3D94 where n is the >sizeof the char, or we can just define column as varchar=3D94 >rli=3D3D# CREATE TABLE test (v1 varchar(100), v2 varchar); >CREATE TABLE >rli=3D3D# \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=20 to fill the field every time (otherwise those right filled blank=20 padding characters will just cause problems). There is no speed performance difference between them, but lots=20 of design advantages in favour of text (it's much more 'future proof'). These ideas are much better explained, and tested here: Regards Gavan Schneider --=20 Sent via pgsql-general mailing list (pgsql-general@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-general