Re: Subqueries in Check() -- Still Intentionally Omitted?

From: Jeff Davis <pgsql(at)j-davis(dot)com>
To: Alvaro Herrera <alvherre(at)commandprompt(dot)com>
Cc: Richard Broersma <richard(dot)broersma(at)gmail(dot)com>, PostgreSQL <pgsql-general(at)postgresql(dot)org>
Subject: Re: Subqueries in Check() -- Still Intentionally Omitted?
Date: 2008-09-02 23:14:32
Message-ID: 1220397272.10936.24.camel@dell.linuxdev.us.dell.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Tue, 2008-09-02 at 18:47 -0400, Alvaro Herrera wrote:
> The problem is that you have to rerun the query to verify that the CHECK
> condition still holds, whenever the table that the CHECK clause is
> checking changes. This is rather problematic, because we'd need to make
> the system aware of such reverse dependencies.

Even if you re-ran the query, how do you avoid the race condition?

For example:
CREATE TABLE foo(
...
CHECK ((SELECT COUNT(*) FROM foo) < 10)
);

If another transaction commits between the time you re-run the query and
the time you commit, the CHECK will be violated.

>From an arbitrary subquery in a CHECK, it's hard to determine what kind
of locking semantics might be necessary for inserting transactions.

I think this is precisely what triggers are for. You define the error
condition and the locking semantics in one procedure.

Regards,
Jeff Davis

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2008-09-02 23:14:57 Re: Index non-usage problem in 8.2.9
Previous Message Jeff Davis 2008-09-02 23:06:56 Re: Subqueries in Check() -- Still Intentionally Omitted?