subselect in CHECK constraint? - Mailing list pgsql-general

From Ian Turner
Subject subselect in CHECK constraint?
Date
Msg-id Pine.LNX.4.21.0009032145310.5371-100000@crafter.house
Whole thread Raw
Responses Re: subselect in CHECK constraint?
RE: subselect in CHECK constraint?
Re: subselect in CHECK constraint?
List pgsql-general
-----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);

I get this error on the second query:

ERROR:  ExecEvalExpr: unknown expression type 108

I'm guessing this means I can't do subselects in CHECK statements.

Let me pose another question, if this is the case:

Say I have a table of warehouses. I then want to have another table keep
track of the products at the warehouse, such that the amount of product at
a warehouse does not exceed the capacity of the warehouse. Which probably
means I would need to have a CHECK statement with a select on each side of
the operator.

Any ideas? :o

I'd look at the source to see what this error means, except that I am on a
dialup.

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

iD8DBQE5syqYfn9ub9ZE1xoRAraCAKCFL7iMHuS62dyYlMMfY84FLG1LvQCgsUYi
T3wCLoCqsojQ0WCDdkLjVPg=
=tJoC
-----END PGP SIGNATURE-----


pgsql-general by date:

Previous
From: Paul Hardiman
Date:
Subject: if (SQLCODE != 0) { sprintf(rMsg,"ERROR: ERROR on SELError Unknown type 'oid8'
Next
From: Alfred Perlstein
Date:
Subject: Re: subselect in CHECK constraint?