Thread: Enum in PostgreSQL - How to
Hello! Could somebody tell me how i would simulate an ENUM columntype (as in MySQL). For example: accountType ENUM('default', 'custom') default='default' How can i do this in PostgreSQL ? Thanks a lot in advance for your time and effort. Best regards, Jürgen
On 7 Apr 2003 at 14:24, Jürgen Hauser wrote: > Could somebody tell me how i would simulate an ENUM columntype (as in > MySQL). For example: > > accountType ENUM('default', 'custom') default='default' > > How can i do this in PostgreSQL ? I tried to answer you on IRC, but you disappeared too quickly. I looked on google, and found this: http://archives.postgresql.org/pgsql-sql/2000-03/msg00020.php -- Dan Langille : http://www.langille.org/
On 7 Apr 2003 at 15:04, Jürgen Hauser wrote: > Hi, > > thanks for your reply. However, the mentioned method doesm't seem to work. > > I also tried something like > > CREATE TABLE accounts > ( > accountid SERIAL, > PRIMARY KEY (accountid), > .... > accountType CHECK ( accountType = 'default' OR accountType = 'custom') > NOT NULL); > > But this doesn't work either.... Please CC all posts to the mailing list. Explaining what "doesn't work" helps, but I think I see the problem. The example shown in the URL provided is incomplete. But looking up that CHECK option will show the correct syntax. Please see http://www.postgresql.org/docs/view.php?version=7.3&idoc=0&file=sql- createtable.html and look in the Examples section: name VARCHAR(40) NOT NULL CHECK (name <> '') You need a variable time, in your case, I suggest TEXT. -- Dan Langille : http://www.langille.org/
On Mon, 2003-04-07 at 14:24, Jürgen Hauser wrote: > Hello! > > Could somebody tell me how i would simulate an ENUM columntype (as in > MySQL). For example: > > accountType ENUM('default', 'custom') default='default' accountType varchar(10) CHECK (accountType='default' or accountType='custom) DEFAULT 'default' -- Vennlig hilsen/Best Regards Nils Olav Selåsdal System Engineer UtelSystems a/s Tlf: 370 45 431 Mob: 416 97 995 w w w . u t e l s y s t e m s . c o m
Yes thank you very much, i just figured it out. At 16:03 07.04.2003 +0200, you wrote: >On Mon, 2003-04-07 at 14:24, Jürgen Hauser wrote: > > Hello! > > > > Could somebody tell me how i would simulate an ENUM columntype (as in > > MySQL). For example: > > > > accountType ENUM('default', 'custom') default='default' >accountType varchar(10) CHECK (accountType='default' or >accountType='custom) DEFAULT 'default' > > >-- >Vennlig hilsen/Best Regards >Nils Olav Selåsdal >System Engineer >UtelSystems a/s >Tlf: 370 45 431 >Mob: 416 97 995 >w w w . u t e l s y s t e m s . c o m > > >---------------------------(end of broadcast)--------------------------- >TIP 4: Don't 'kill -9' the postmaster