Re: EVAL and SET equivalents in PostgreSQL

From: Stephan Szabo <sszabo(at)megazone23(dot)bigpanda(dot)com>
To: Alvaro Herrera <alvherre(at)atentus(dot)com>
Cc: Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us>, Lynn David Newton <lynn(dot)newton(at)cox(dot)net>, <pgsql-general(at)postgresql(dot)org>
Subject: Re: EVAL and SET equivalents in PostgreSQL
Date: 2002-07-04 06:26:44
Message-ID: 20020703232043.F14152-100000@megazone23.bigpanda.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general


On Wed, 3 Jul 2002, Alvaro Herrera wrote:

> Bruce Momjian dijo:
>
> > Sure, use CHECK constraints on the column. That is the ANSI standard
> > way.
> >
> > gender CHAR(1) CHECK (gender IN ('M','F')),
>
> That's the solution for the ENUM MySQL datatype, but the SET datatype
> allows one to have multiple values in the column (or that's what I
> understood in the original message).
>
> In PostgreSQL, you could use an array to store multiple values. I don't
> know if one could set up a CHECK constraint so that every element in a
> varchar array is checked against a predefined set. Maybe it can be done
> at insertion time using a trigger?

Should work find if you've got a function that does the check. Using
contrib/array you could do the ugly check (col *='M' or col *='F')
which at least seems to work on current sources. You could do something
with regexs or build another function that checks a list of values.
However, that doesn't prevent you from having duplicates (I don't know how
MySQL's set works).

Or a details table and options table with the appropriate foreign keys.

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Manfred Koizar 2002-07-04 06:56:04 Re: One source of constant annoyance identified
Previous Message Tom Lane 2002-07-04 04:49:35 Re: epoch from date field