Re: enumerated type.. - Mailing list pgsql-general

From Michael Kleiser
Subject Re: enumerated type..
Date
Msg-id 40FBDEB0.2020405@webde-ag.de
Whole thread Raw
In response to enumerated type..  ("raptor@tvskat.net" <raptor@tvskat.net>)
Responses Re: enumerated type..  (Bruno Wolff III <bruno@wolff.to>)
List pgsql-general
I don`t know, if there is a special feature in postgresql for this.
The standard SQL-way is to create a lookup-table and define a foreign-key to it.

create table states( state_id int primary key not null
                    , state_text varchar(30) not null
                    , constraint uk_states_state_text unique( state_text ) );


create table states( state_id int primary key not null , state_text varchar(30) not null );
alter table states add constraint uk_states_state_text unique( state_text );

create table your_table (
...
   state_id int not null
, constraint fk_yt_state_id foreign key (state_id) references  states
);




raptor@tvskat.net schrieb:
> hi,
>
> Is it possible in Postgre to have enum type,  so that later table fileld get values from 1-6 (saving space)
>
> 1 - statex
> 2 - stateY
> 3 - stateZ
>
> something like that and then constrain on this enum type..
>
> tia
>
> ---------------------------(end of broadcast)---------------------------
> TIP 2: you can get off all lists at once with the unregister command
>     (send "unregister YourEmailAddressHere" to majordomo@postgresql.org)


pgsql-general by date:

Previous
From: Damon Hart
Date:
Subject: special table queries slow until dump/restore
Next
From: Stephan Szabo
Date:
Subject: Re: Index Using