Re: CHECK versus a Table for an enumeration

From: Pavel Stehule <stehule(at)kix(dot)fsv(dot)cvut(dot)cz>
To: Melanie Bergeron <mbergeron_pg(at)globeecom(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: CHECK versus a Table for an enumeration
Date: 2003-12-23 07:17:05
Message-ID: Pine.LNX.4.44.0312230812110.2523-100000@kix.fsv.cvut.cz
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hello Melanie

If your set of items will by static and small, then you can use CHECK
constraint. I use it for five, items itemes.

You can write more simple this constraint

...
user_type TEXT NOT NULL CHECK (user_type IN ('Root','Admin','Standard')),

regards
Pavel Stehule

On Mon, 22 Dec 2003, Melanie Bergeron wrote:

> Hi all!
>
> I want to know what's better between these 2 solutions :
>
> CREATE TABLE user (
> ...
> user_type text CHECK(user_type='Root' OR user_type = 'Admin' OR
> user_type = 'Standard'));
>
> or the following :
>
> CREATE TABLE user_type(
> user_type_id integer PRIMARY KEY,
> user_type_desc text);
>
> CREATE TABLE user (
> ...
> user_type_id integer,
> CONSTRAINT user_type_exists FOREIGN KEY (user_type_id) REFERENCES
> user(user_type_id));
>
> I am really confused so I'll wait for your advices.
>
> Thanks,
>
> Melanie
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 5: Have you checked our extensive FAQ?
>
> http://www.postgresql.org/docs/faqs/FAQ.html
>

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Pavel Stehule 2003-12-23 08:03:04 Solved: questions about tsearch2 (for czech language)
Previous Message George Gensure 2003-12-23 07:06:14 ecpg question