Re: enforce null only
Posted in 2009
Thanks !!
That works for me too.
----- Original Message -----
From: "Jonathan Leffler" <jleffler.iiug@gmail.com>
Sent: Mon, February 23, 2009 17:47
Subject:Re: enforce null only
On Fri, Feb 20, 2009 at 1:09 PM, Floyd Wellershaus <floyd@fwellers.com>
wrote:
> Our developers are asking for a way to enforce that a particular field
> cannot contain any values ( null ), unless another field has a certain
value
> in it ( "S" ).
>
> I assume the only way to do this is to have a pre-insert trigger that
calls
> a stored procedure, but is that right, or is there some way to manipulate a
> check constraint to do it ?
CREATE TABLE t
(
i SERIAL,
a CHAR(1) NOT NULL CHECK (a IN ('S', 'T')),
b CHAR(5),
CHECK (b IS NULL OR a = 'S')
);
INSERT INTO t(i,a,b) VALUES(0,'T','a');Error: SQL -530: Check constraint (jleffler.c471_1339) failed.
INSERT INTO t(i,a,b) VALUES(0, 'S', 'aaa');
Works for me - IDS 11.50. Does it work for you?
--
Jonathan Leffler #include <disclaimer.h>
Email: jleffler@earthlink.net, jleffler@us.ibm.com
Guardian of DBD::Informix v2008.0513 -- http://dbi.perl.org/
"Blessed are we who can laugh at ourselves, for we shall never cease
to be amused."
NB: Please do not use this email for correspondence.
I don't necessarily read it every week, even.
----- End of original message -----