X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 7895C52985 for ; Wed, 29 Jun 2005 04:09:29 -0300 (ADT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 71828-08 for ; Wed, 29 Jun 2005 07:09:27 +0000 (GMT) Received: from zproxy.gmail.com (zproxy.gmail.com [64.233.162.205]) by svr1.postgresql.org (Postfix) with ESMTP id C76145297F for ; Wed, 29 Jun 2005 04:09:25 -0300 (ADT) Received: by zproxy.gmail.com with SMTP id 8so442532nzo for ; Wed, 29 Jun 2005 00:09:27 -0700 (PDT) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:reply-to:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=bcY0059rgg5K9Df4YI6kzmveI5GFWuPpyNpLE7eEHUbnRccD4QnFzmdI9MZUxEN+WBMssuWCbgGdsOtoHzUVq/TL2Y2gLL2fT8YWocqKHA0tpLaKmMCgmjpCp/V3NtMhLCTdyv8PHZAASLOXxHCHM+D47c+qHBZc4cghmie0bbw= Received: by 10.36.222.48 with SMTP id u48mr812445nzg; Wed, 29 Jun 2005 00:09:27 -0700 (PDT) Received: by 10.36.22.20 with HTTP; Wed, 29 Jun 2005 00:09:27 -0700 (PDT) Message-ID: <758d5e7f05062900097ed5151c@mail.gmail.com> Date: Wed, 29 Jun 2005 09:09:27 +0200 From: Dawid Kuroczko Reply-To: Dawid Kuroczko To: =?ISO-8859-1?Q?Mart=EDn_Marqu=E9s?= Subject: Re: ENUM like data type Cc: PFC , Mike Rylander , pgsql-sql@postgresql.org, PostgreSQL-development In-Reply-To: <200506281522.25124.martin@bugs.unl.edu.ar> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline References: <11bgc1oblfasq3d@corp.supernews.com> <200506281522.25124.martin@bugs.unl.edu.ar> X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.628 tagged_above=0 required=5 tests=AWL, FROM_ENDS_IN_NUMS, RCVD_BY_IP X-Spam-Level: X-Archive-Number: 200506/347 X-Sequence-Number: 21948 On 6/28/05, Mart=EDn Marqu=E9s wrote: > El Mar 28 Jun 2005 13:58, PFC escribi=F3: > > Personnally I use one table which has columns (domain, name) and = which > > stores all enum values for all different enums. > > I have then CHECK( is_in_domain( column, 'domain_name' )) which i= s a > > simple function which checks existence of the value in this domain (SEL= ECT > > 1 FROM domains WHERE domain=3D$2 AND name=3D$1 LIMIT 1) for instance. > > You can also use integers. >=20 > I personally think that the ENUM data type is for databases that are not = well > designed. So, if you see the need for ENUM, that means you need to re-thi= nk > your data design. I seem to remember some discussion here, half a year ago perhaps which was about something similar (while not exactly). I mean it=20 I think it someone said that DB2 (I am not sure about that one) has a feature that enables it to normalize the table behind the scenes. As I remember it, it works somewhere along the lines of: -- you create table CREATE TABLE foo ( when timestamptz, useragent some_data_type_perhaps ); ...and RDBMS will create a lookup table for useragents for you, with serial key, etc, etc. And in our foo table useragent will be kept as a reference to that lookup table. When you do a select, lookup table will be consulted behind the scenes, etc, etc. All this is doable with RULEs and VIEWs (and triggers for populating). Well, what MRB had in mind was more like a special subcase of such approach (lookup table with "read-only" keys), but I think such a lookup table would be benefitial for many users, especially when dealing with large tables. Incidentally, does it qualify for todo? Or maybe its already there? Regards, Dawid