Re: subselect in CHECK constraint?

From: Alfred Perlstein <bright(at)wintelcom(dot)net>
To: Ian Turner <vectro(at)pipeline(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: subselect in CHECK constraint?
Date: 2000-09-04 05:44:53
Message-ID: 20000903224453.H18862@fw.wintelcom.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

* Ian Turner <vectro(at)pipeline(dot)com> [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, 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.

Two things:

1) i'm pretty sure this subselect can be rewritten as:
SELECT SUM(t.a) < 1000 FROM test t WHERE t.b = b
to return a boolean.

2) you can probably get away with using a plpgsql function
that has more logic in it.

I'm not saying that subselects do or do not work, just offering
some alternative advice.

-Alfred

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Jarmo Paavilainen 2000-09-04 07:20:10 Updating cursors
Previous Message Ian Turner 2000-09-04 04:52:38 subselect in CHECK constraint?