subselect in CHECK constraint?

From: Ian Turner <vectro(at)pipeline(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: subselect in CHECK constraint?
Date: 2000-09-04 04:52:38
Message-ID: Pine.LNX.4.21.0009032145310.5371-100000@crafter.house
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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-----

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Alfred Perlstein 2000-09-04 05:44:53 Re: subselect in CHECK constraint?
Previous Message Paul Hardiman 2000-09-04 04:36:35 if (SQLCODE != 0) { sprintf(rMsg,"ERROR: ERROR on SELError Unknown type 'oid8'