Field Constraints

From: Joseph Maxwell <jemaxwell(at)jaymax(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: Field Constraints
Date: 2002-03-06 19:47:08
Message-ID: 3C86723C.3BA5B604@jaymax.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hello,
I have created a DB and TABLE but would like to constrain one field to
accept either "YES" or "NO" only. How can I set this up?
I have tried various syntactic constructs of

Prior_Rx varchar(3) NULL CHECK ('Yes', 'No'),
Prior_Rx varchar(3) NULL CHECK (VALUE 'Yes', 'No'),
Prior_Rx varchar(3) NULL CHECK ('Yes', 'No'),
Prior_Rx varchar(3) NULL CONSTRAINT (CHECK (VALUE
'Yes', 'No')),
Prior_Rx varchar(3) NULL CONSTRAINT (CHECK ('Yes',
'No')),
Prior_Rx varchar(3) NULL CONSTRAINT (CHECK (VALUE Yes,
No)),
Prior_Rx varchar(3) NULL CONSTRAINT (CHECK (Yes, No)),

Prior_Rx varchar(3) NULL CONSTRAINT (CHECK (Yes OR
No)),
Prior_Rx varchar(3) NULL CHECK (Yes OR No),
Prior_Rx varchar(3) NULL CHECK ('Yes' OR 'No'),

Obviously they were all wrong, could someone advise?
Thanks

-- Joe --
PS---------------------------------------------------------------------------------------

Just learned that the datatype should be 'bool' in this case

haven't tested it yet

But had I wanted to restrict it to say either mike or john, or even one
of a list say, 'tea', 'cofee', 'chocolate' or 'espresso', how should
that be constructed?

Responses

Browse pgsql-general by date

  From Date Subject
Next Message jason_donmoyer 2002-03-06 19:47:22 Best mechanism for change notification
Previous Message Vivek Khera 2002-03-06 19:16:41 Re: Export a database or a table from a database