Received: from localhost (mx1.hub.org [200.46.208.251]) by postgresql.org (Postfix) with ESMTP id A74D09FA344 for ; Wed, 18 Oct 2006 06:31:54 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.208.251]) (amavisd-new, port 10024) with ESMTP id 41884-04 for ; Wed, 18 Oct 2006 06:31:52 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey- Received: from svr4.postgresql.org (svr4.postgresql.org [66.98.251.159]) by postgresql.org (Postfix) with ESMTP id E44F19FA2CA for ; Wed, 18 Oct 2006 06:31:51 -0300 (ADT) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.3 Received: from relay.icomedias.com (relay.icomedias.com [62.99.232.66]) by svr4.postgresql.org (Postfix) with ESMTP id 488E35AF04F for ; Wed, 18 Oct 2006 09:31:47 +0000 (GMT) Received: from loki.icomedias.com ([10.192.17.128]) by relay.icomedias.com (8.13.6/8.13.6) with ESMTP id k9I9VjEC008250; Wed, 18 Oct 2006 11:31:45 +0200 From: Mario Weilguni To: Alexander Staubo Subject: Re: Optimization of this SQL sentence Date: Wed, 18 Oct 2006 11:31:44 +0200 User-Agent: KMail/1.9.4 Cc: pgsql-performance@postgresql.org, Ruben Rubio References: <45349CDF.3090002@rentalia.com> <200610171729.19596.mweilguni@sime.com> In-Reply-To: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <200610181131.44840.mweilguni@sime.com> X-Scanned-By: MIMEDefang 2.54 on 10.192.64.200 X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=1.088 tagged_above=0 required=5 tests=AWL, SPF_SOFTFAIL X-Spam-Level: * X-Archive-Number: 200610/343 X-Sequence-Number: 21472 Am Dienstag, 17. Oktober 2006 17:50 schrieb Alexander Staubo: > On Oct 17, 2006, at 17:29 , Mario Weilguni wrote: > > > > Enforcing length constraints with varchar(xyz) is good database > > design, not a > > bad one. Using text everywhere might be tempting because it works, > > but it's > > not a good idea. > > Enforcing length constraints is generally a bad idea because it > assumes you know the data domain as expressed in a quantity of > characters. Off the top of your head, do you know the maximum length > of a zip code? A street address? The name of a city? It's not a bad idea. Usually I use postal codes with 25 chars, and never had any problem. With text, the limit would be ~1 GB. No matter how much testing in the application happens, the varchar(25) as last resort is a good idea. And in most cases, the application itself limits the length, and thus it's good to reflect this in the database design. Feel free to use text anywhere for your application, and feel free to use numeric(1000) instead of numeric(4) if you want to be prepared for really long numbers, but don't tell other people it's bad database design - it isn't.