Re: subselect in CHECK constraint? - Mailing list pgsql-general

From Ian Turner
Subject Re: subselect in CHECK constraint?
Date
Msg-id Pine.LNX.4.21.0009040933050.612-100000@crafter.house
Whole thread Raw
In response to Re: subselect in CHECK constraint?  (Tom Lane <tgl@sss.pgh.pa.us>)
Responses Re: subselect in CHECK constraint?  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-general
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

>     CHECK (testconstraint(a, b))

Uhhh. I get no errors, but it dosen't work, either. Consider:

CREATE FUNCTION testconstraint(int,int) RETURNS bool AS '
BEGIN
    RETURN (select sum(a) FROM test WHERE b = $2) < 1000;
END;
' LANGUAGE 'plpgsql';

CREATE TABLE test (a int, b int, CHECK (testconstraint(a,b)));

INSERT INTO test (a,b) VALUES (1100, 1);

SELECT * FROM test;

Yielding:

  a   | b
- ------+---
 1100 | 1
(1 row)

which clearly does not satisfy the constraint.

Ian
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.1 (GNU/Linux)
Comment: For info see http://www.gnupg.org

iD8DBQE5s8/6fn9ub9ZE1xoRAuiRAKCHh/wWSl7uYzhJGWnc7kc0OxqZogCgpMCN
MdTBSXm7w0C4R4Ghh77+8ok=
=nik7
-----END PGP SIGNATURE-----


pgsql-general by date:

Previous
From: "cuke"
Date:
Subject: Re:
Next
From: Tom Lane
Date:
Subject: Re: subselect in CHECK constraint?