From: Alexander M. Pravking <fduch@antar.bryansk.ru>
To: T E Schmitz <mailreg@numerixtechnology.de>
Cc: pgsql-sql <pgsql-sql@postgresql.org>
Subject: Re: CHECK col A not NULL if col B='x'
Date: Tue, 28 Sep 2004 18:15:04 +0400
Message-ID: <20040928141504.GA17595@dyatel.antar.bryansk.ru> (raw)
In-Reply-To: <41596EDA.4030909@numerixtechnology.de>
References: <41596EDA.4030909@numerixtechnology.de>
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.
fduch@~=# CREATE TABLE test (
fduch@~(# a integer check (case when b = 'x' then a is not null else true end),
fduch@~(# b text);
CREATE TABLE
fduch@~=# INSERT INTO test VALUES (null, '123');
INSERT 107538 1
fduch@~=# INSERT INTO test VALUES (null, 'x');
ERROR: new row for relation "test" violates check constraint "test_a"
fduch@~=# INSERT INTO test VALUES (1, 'x');
INSERT 107539 1
--
Fduch M. Pravking
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-sql@postgresql.org
Cc: fduch@antar.bryansk.ru, mailreg@numerixtechnology.de
Subject: Re: CHECK col A not NULL if col B='x'
In-Reply-To: <20040928141504.GA17595@dyatel.antar.bryansk.ru>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox