From: Martin Marques <martin@bugs.unl.edu.ar>
To: 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 11:12:02 -0300
Message-ID: <200409281112.02986.martin@bugs.unl.edu.ar> (raw)
In-Reply-To: <41596EDA.4030909@numerixtechnology.de>
References: <41596EDA.4030909@numerixtechnology.de>
El Mar 28 Sep 2004 11:02, T E Schmitz escribió:
> Hello,
>
> Is it possible to set up a table CHECK, which ensures that column A is
> NOT NULL if column B = 'x' ?
CONSTRAINT constraint_name ]
CHECK (expression)
CHECK (expression)
The CHECK clause specifies an expression producing a Boolean result which new
or updated rows must satisfy for an insert or update operation to succeed. A
check constraint specified as a column constraint should reference that
column's value only, while an expression appearing in a table constraint may
reference multiple columns.
So I would say that it should be:
CONSTRAINT somename CHECK (B <> 'x' OR A IS NOT NULL)
(use a logical table to build the correct logical expression)
--
11:05:01 up 16 days, 1:23, 4 users, load average: 1.26, 0.70, 1.04
-----------------------------------------------------------------
Martín Marqués | select 'mmarques' || '@' || 'unl.edu.ar'
Centro de Telematica | DBA, Programador, Administrador
Universidad Nacional
del Litoral
-----------------------------------------------------------------
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: martin@bugs.unl.edu.ar, mailreg@numerixtechnology.de
Subject: Re: CHECK col A not NULL if col B='x'
In-Reply-To: <200409281112.02986.martin@bugs.unl.edu.ar>
* 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