Received: from maia.hub.org (maia-2.hub.org [200.46.204.251]) by mail.postgresql.org (Postfix) with ESMTP id 77A6EB5DBD8 for ; Fri, 5 Aug 2011 10:02:43 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.251]) (amavisd-maia, port 10024) with ESMTP id 47292-04 for ; Fri, 5 Aug 2011 13:02:36 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from lo.gmane.org (lo.gmane.org [80.91.229.12]) by mail.postgresql.org (Postfix) with ESMTP id 9B526B5D800 for ; Fri, 5 Aug 2011 10:02:36 -0300 (ADT) Received: from list by lo.gmane.org with local (Exim 4.69) (envelope-from ) id 1QpK2q-0004Ek-Lk for pgsql-sql@postgresql.org; Fri, 05 Aug 2011 15:02:32 +0200 Received: from ip-118-90-1-184.xdsl.xnet.co.nz ([118.90.1.184]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Fri, 05 Aug 2011 15:02:32 +0200 Received: from jasen by ip-118-90-1-184.xdsl.xnet.co.nz with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Fri, 05 Aug 2011 15:02:32 +0200 X-Injected-Via-Gmane: http://gmane.org/ To: pgsql-sql@postgresql.org From: Jasen Betts Subject: Re: Generic design: char vs varchar primary keys Date: 5 Aug 2011 12:40:19 GMT Organization: Dis (not Dat) Organisation Lines: 29 Message-ID: References: <201108032040.17628.raju@linux-delhi.org> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Complaints-To: usenet@dough.gmane.org X-Gmane-NNTP-Posting-Host: ip-118-90-1-184.xdsl.xnet.co.nz X-Face: ?)Aw4rXwN5u0~$nqKj`xPz>xHCwgi^q+^?Ri*+R(&uv2=E1Q0Zk(>h!~o2ID@6{uf8s; a +M[5[U[QT7xFN%^gR"=tuJw%TXXR'Fp~W; (T"1(739R%m0Yyyv*gkGoPA.$b,D.w:z+<'"=-lVT?6 {T?=R^:W5g|E2#EhjKCa+nt":4b}dU7GYB*HBxn&Td$@f%.kl^:7X8rQWd[NTc"P"u6nkisze/Q; 8 "9Z{peQF,w)7UjV$c|RO/mQW/NMgWfr5*$-Z%u46"/00mx-,\R'fLPe.)^ User-Agent: slrn/pre1.0.0-18 (Linux) X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-2.704 tagged_above=-5 required=5 tests=BAYES_00=-1.9, RP_MATCHES_RCVD=-0.804 X-Spam-Level: X-Archive-Number: 201108/20 X-Sequence-Number: 35688 On 2011-08-03, Raj Mathur (=?utf-8?b?4KSw4KS+4KSc?= =?utf-8?b?IOCkruCkvuCkpeClgeCksA==?=) wrote: > Hi, > > Can you point me to any pages that explain the difference between using, > say CHAR(8) vs VARCHAR(8) as the primary key for a table? Is there any > impact on the database in terms of: look in the data types chapter of the manual > - Speed of indexed retrieval > - Speed of join from a referencing table > - Storage (I presume VARHAR(8) would have a slight edge, in general) > - Any other issue Unless you need the padding, and/or the length constraints use text. ("usr/share/doc/postgresql-doc-8.4/html/datatype-character.html") . Tip: There is no performance difference among these three types, . apart from increased storage space when using the blank-padded type, . and a few extra CPU cycles to check the length when storing into a . length-constrained column. While character(n) has performance . advantages in some other database systems, there is no such advantage . in PostgreSQL; in fact character(n) is usually the slowest of the . three because of its additional storage costs. In most situations text . or character varying should be used instead. -- ⚂⚃ 100% natural