Re: Does PostgreSQL support SET or ENUM data types?

From: Alexey Borzov <borz_off(at)rdw(dot)ru>
To: Maxim Maletsky <maxim(at)japaninc(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Does PostgreSQL support SET or ENUM data types?
Date: 2001-06-22 08:29:51
Message-ID: 1494001965.20010622122951@rdw.ru
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Greetings, Maxim!

At 22.06.2001, 09:20, you wrote:
MM> I am not a very great PostgreSQL user, but I know mySQL. In mySQL we have
MM> SET and ENUM.
MM> I now need something like this in PostgreSQL.
Trust me: you don't. These are ugly crutches to circumvent mySQL's
complete lack of referential integrity. These are unportable, too.

`Emulating` the SET:
------------------------------------------------
create table foo (
foo_id ...,
foo1 ...,
foo2 ...,

primary key (foo_id)
)

create table foo_set_values (
set_id ...,
set_value ...,

primary key (set_id)
)

create table foo_set (
foo_id ...,
set_id ...,

primary key (foo_id, set_id),
foreign key (foo_id) references foo,
foreign key (set_id) references foo_set_values
)
------------------------------------------------

`Emulating` the ENUM (with lookup table)
------------------------------------------------
create table bar_enum (
enum_id ...,
enum_value ...,

primary key (enum_id)
)

create table bar (
bar_id ...,
bar1 ...,
bar2 ...,
enum_id ...,

primary key (bar_id),
foreign key (enum_id) references bar_enum
)
------------------------------------------------

`Emulating` the ENUM (with CHECK)
------------------------------------------------
create table bar (
bar_id ...,
bar1 ...,
bar2 ...,
bar_enum ... CHECK bar_enum IN ('one', 'two', 'three'),

primary key (bar_id)
)
------------------------------------------------

These ARE portable. To anywhere except mySQL.

--
Yours, Alexey V. Borzov, Webmaster of RDW.ru

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Richard Huxton 2001-06-22 08:30:05 Re: where's the reference to a view, here?
Previous Message Andreas Tille 2001-06-22 07:36:23 Re: Authentification