[postgis-users] Adding constraint
Mike Toews
mwtoews at gmail.com
Wed Apr 25 14:57:44 PDT 2012
Add a check constraint with the logic:
ALTER TABLE test
ADD CONSTRAINT aaa_atrib_2_not_null CHECK (
CASE
WHEN attrib_1 = 'AAA'::text THEN attrib_2 IS NOT NULL
ELSE true
END);
-Mike
On 26 April 2012 08:34, Piotr Pachół <piotrpachol at gmail.com> wrote:
> Hello,
> Is it possible to add constraint to second attribute of table only in the
> situation when first attribute of table equals specified value ?
> I give an example:
>
> CREATE TABLE test (
> attrib_1 text,
> attrib_2 text
> );
> INSERT INTO test VALUES ('AAA', 'QQQ');
> INSERT INTO test VALUES ('BBB', 'PPP');
>
>
> So is it possible to add constraint (for instance NOT NULL) to attrib_2
> column if attrib_1 = 'AAA'
>
> Regards,
> Piotr
>
> _______________________________________________
> postgis-users mailing list
> postgis-users at postgis.refractions.net
> http://postgis.refractions.net/mailman/listinfo/postgis-users
More information about the postgis-users
mailing list