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 6205E529DA for ; Tue, 28 Jun 2005 08:22:36 -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 00698-04 for ; Tue, 28 Jun 2005 11:22:34 +0000 (GMT) Received: from wproxy.gmail.com (wproxy.gmail.com [64.233.184.207]) by svr1.postgresql.org (Postfix) with ESMTP id C53F6529C8 for ; Tue, 28 Jun 2005 08:22:32 -0300 (ADT) Received: by wproxy.gmail.com with SMTP id i4so537759wra for ; Tue, 28 Jun 2005 04:22:36 -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:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=YBh8/rXIGxhVNUiU6/QStymLkQ3A5rdxGAXAqbntolwdtmkz3dPRqc7g4eof/3wR3bzCiaBj20lNJtYk1J/i5r+VK4XQD2/r5GocqEXwWSEypMDQ7x7WqOYoBfWJKCtGw4nooLJKZShl1Sv9bszE0eP3UC7tSE0UeCFMy+/MbqA= Received: by 10.54.119.18 with SMTP id r18mr51596wrc; Tue, 28 Jun 2005 04:22:36 -0700 (PDT) Received: by 10.54.149.6 with HTTP; Tue, 28 Jun 2005 04:22:36 -0700 (PDT) Message-ID: Date: Tue, 28 Jun 2005 11:22:36 +0000 From: Mike Rylander Reply-To: Mike Rylander To: pgsql-sql@postgresql.org Subject: Re: ENUM like data type In-Reply-To: <11bgc1oblfasq3d@corp.supernews.com> 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> X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.067 tagged_above=0 required=5 tests=AWL, RCVD_BY_IP X-Spam-Level: X-Archive-Number: 200506/334 X-Sequence-Number: 21935 On 6/21/05, MRB wrote: > Hi All, >=20 > I have something in mind I'm not certain is do-able. >=20 > I'm working with a lot of data from MySQL where the MySQL ENUM type is us= ed. >=20 MySQL's ENUM is basically a wrapper for CHECK. You can use a CHECK constraint like this: CREATE TABLE test( testfield TEXT CHECK (testfield IN( 'Bits', 'of', 'data')) ); > This is not a big problem per se but creating the proper lookup tables > is becoming a bit tedious so I was hoping to make something better of it. >=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 tables > the same way the SERIAL type triggers creation of a sequence and returns > an int with the right default value. Although you can't create a generic type to handle this, you can create a DOMAIN to wrap up your constraint for each "enum" type field that you want: CREATE DOMAIN fruit AS TEXT CHECK (VALUE IN ('apple','orange','banana')); CREATE TABLE eat ( food fruit ); http://www.postgresql.org/docs/8.0/interactive/sql-createdomain.html Hope that helps. --=20 Mike Rylander mrylander@gmail.com GPLS -- PINES Development Database Developer http://open-ils.org