On Tue, Sep 28, 2004 at 03:02:02PM +0100, T E Schmitz wrote:
> Hello,
> 
> Is it possible to set up a table CHECK, which ensures that column A is 
> NOT NULL if column B = 'x' ?

Sure.

[EMAIL PROTECTED] CREATE TABLE test (
[EMAIL PROTECTED](# a integer check (case when b = 'x' then a is not null else true 
end),
[EMAIL PROTECTED](# b text);
CREATE TABLE
[EMAIL PROTECTED] INSERT INTO test VALUES (null, '123');
INSERT 107538 1
[EMAIL PROTECTED] INSERT INTO test VALUES (null, 'x');
ERROR:  new row for relation "test" violates check constraint "test_a"
[EMAIL PROTECTED] INSERT INTO test VALUES (1, 'x');
INSERT 107539 1

-- 
Fduch M. Pravking

---------------------------(end of broadcast)---------------------------
TIP 8: explain analyze is your friend

Reply via email to