Table definitions using CHECK and DEFAULT - Mailing list pgsql-general

From Matthew L. Wirges
Subject Table definitions using CHECK and DEFAULT
Date
Msg-id 20011104184058.B8831@basm.cerias.purdue.edu
Whole thread Raw
Responses Re: Table definitions using CHECK and DEFAULT  ("Command Prompt, Inc." <pgsql-general@commandprompt.com>)
Re: Table definitions using CHECK and DEFAULT  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-general
I am adding PostgreSQL support to some software that I've been
developing and I've hit a few snags.
I've found that MySQL's "ENUM" can be emulated with PostgreSQL's
"CHECK".  Unfortunately it appears that I cannot use both the DEFAULT
modifier and the check modifier at the same time.

This line:
address_type VARCHAR(30) DEFAULT 'unknown' NOT NULL CHECK(address_type
IN ("unknown", "forged", "proxy", "temporary", "permanent"))

gives the error:
psql:IRDB_POSTGRES:69: ERROR:  Attribute 'unknown' not found

If I write the definition without DEFAULT it works fine, if I write it
without the CHECK statement it works fine too..
(I've also split up the column definition and the check definition, i.e.
address_type VARCHAR(30) DEFAULT 'unknown' NOT NULL,
CHECK(address_type IN ("unknown", "forged", "proxy", "temporary", "permanent"))
)

Is the SQL wrong?  Is it just not possible to do this? Or is this a
possible bug?

Any help is appreciated!

--
Matthew Wirges
  Developer::CERIAS Incident Response Database
  https://cirdb.cerias.purdue.edu/
  wirges@cerias.purdue.edu

pgsql-general by date:

Previous
From: "Command Prompt, Inc."
Date:
Subject: Re: Got error on CREATE TABLE AS (+Bug?)
Next
From: "Said Badrul Nahar"
Date:
Subject: newbie question