From: | Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us> |
---|---|
To: | Lynn David Newton <lynn(dot)newton(at)cox(dot)net> |
Cc: | pgsql-general(at)postgresql(dot)org |
Subject: | Re: EVAL and SET equivalents in PostgreSQL |
Date: | 2002-07-03 20:21:35 |
Message-ID: | 200207032021.g63KLZs02514@candle.pha.pa.us |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
Sure, use CHECK constraints on the column. That is the ANSI standard
way.
gender CHAR(1) CHECK (gender IN ('M','F')),
---------------------------------------------------------------------------
Lynn David Newton wrote:
>
> This is no doubt asked frequently, but I have exactly two days
> experience with PostgreSQL, and am hot on a project for which I need a
> more-or-less immediate answer.
>
> Most of my previous DB experience has been with MySQL, which supported
> ENUM('value1','value2'...) data types, to allow a column to be
> assigned the value of exactly one item from the list, and also the
> SET('value1','value2',...) type to allow zero or more members of the
> set of values.
>
> I need this functionality or something equivalent in a DB I'm setting
> up on a project, and a half day of rumbling around in man pages and
> printed documentation has yielded no obvious answer. I did learn about
> creating arrays, but that's not exactly what I want.
>
> If I try to INSERT an illegel value for a SET or ENUM field, MySQL
> will return an error message, which is what you want it to do.
>
> Without that, you have to add a layer of programming to intercept the
> values that are coming in and verify that it's good stuff -- lots of
> trouble that I'd like to avoid if possible.
>
> I'm asking this group because I know that surely I am not the first
> migrant from MySQL to come up against this problem, and suspect the
> answer is common knowledge that I have not yet groked.
>
> Many thanks for any insights shared.
>
> --
> Lynn David Newton
> Phoenix, AZ
>
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 5: Have you checked our extensive FAQ?
>
> http://www.postgresql.org/users-lounge/docs/faq.html
>
>
>
--
Bruce Momjian | http://candle.pha.pa.us
pgman(at)candle(dot)pha(dot)pa(dot)us | (610) 853-3000
+ If your life is a hard drive, | 830 Blythe Avenue
+ Christ can be your backup. | Drexel Hill, Pennsylvania 19026
From | Date | Subject | |
---|---|---|---|
Next Message | Nigel J. Andrews | 2002-07-03 20:44:06 | Re: Temporal Event |
Previous Message | viksa verma | 2002-07-03 19:56:21 | connecting to the database |