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 CC9E152835 for ; Tue, 28 Jun 2005 15:46:21 -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 19191-03 for ; Tue, 28 Jun 2005 18:46:19 +0000 (GMT) Received: from koolancexeon.g2switchworks.com (mail.g2switchworks.com [63.87.162.25]) by svr1.postgresql.org (Postfix) with ESMTP id 708BD529AA for ; Tue, 28 Jun 2005 15:46:18 -0300 (ADT) Received: mail.g2switchworks.com 10.10.1.8 from 10.10.1.37 10.10.1.37 via HTTP with MS-WebStorage 6.5.6944 Received: from state.g2switchworks.com by mail.g2switchworks.com; 28 Jun 2005 13:46:19 -0500 Subject: Re: ENUM like data type From: Scott Marlowe To: =?ISO-8859-1?Q?Mart=EDn_Marqu=E9s?= Cc: PFC , Mike Rylander , pgsql-sql@postgresql.org In-Reply-To: <200506281522.25124.martin@bugs.unl.edu.ar> References: <11bgc1oblfasq3d@corp.supernews.com> <200506281522.25124.martin@bugs.unl.edu.ar> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Message-Id: <1119984378.8208.114.camel@state.g2switchworks.com> Mime-Version: 1.0 X-Mailer: Ximian Evolution 1.4.6 (1.4.6-2) Date: Tue, 28 Jun 2005 13:46:18 -0500 X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.005 tagged_above=0 required=5 tests=AWL X-Spam-Level: X-Archive-Number: 200506/343 X-Sequence-Number: 21944 On Tue, 2005-06-28 at 13:22, Mart=C3=ADn Marqu=C3=A9s wrote: > El Mar 28 Jun 2005 13:58, PFC escribi=C3=B3: > >=20 > > >> Here is where I get uncertain as to if this is possible. My idea is = to > > >> create a pseudo type that triggers the creation of it's lookup table= s > > >> the same way the SERIAL type triggers creation of a sequence and ret= urns > > >> an int with the right default value. > >=20 > > Personnally I use one table which has columns (domain, name) and which= =20 > > stores all enum values for all different enums. > > I have then CHECK( is_in_domain( column, 'domain_name' )) which is a =20 > > simple function which checks existence of the value in this domain (SEL= ECT =20 > > 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=20 > designed. So, if you see the need for ENUM, that means you need to re-thi= nk=20 > your data design. I would generally agree, however, a pseudo type like serial that created the properly fk'd table with all the options in it would be quite nice to have.