* Ian Turner [EMAIL PROTECTED] [000903 22:37] wrote:
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1
When I try to do this:
CREATE TABLE test (
a Integer,
b Integer,
CHECK ((SELECT SUM(t.a) FROM test t WHERE t.b = b) 1000)
);
INSERT INTO test (a, b) VALUES (100,
-Original Message-
From: Ian Turner
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1
When I try to do this:
CREATE TABLE test (
a Integer,
b Integer,
CHECK ((SELECT SUM(t.a) FROM test t WHERE t.b = b) 1000)
);
INSERT INTO test (a, b) VALUES (100, 2);
-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
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1
Also, as several other people already pointed out, a constraint
involving a select could be violated in many ways including alteration
or removal of tuples in other tables. We only evaluate check
constraints when we insert/update tuples in the