Re: Best way to prevent overlapping dates - Mailing list pgsql-general

From Michael Glaesemann
Subject Re: Best way to prevent overlapping dates
Date
Msg-id F6BA8F44-EE0D-4007-96C5-8B5A3D98CA00@seespotcode.net
Whole thread Raw
In response to Best way to prevent overlapping dates  ("Andrus" <kobruleht2@hot.ee>)
Responses Re: Best way to prevent overlapping dates
List pgsql-general
On May 25, 2007, at 3:22 , Andrus wrote:

> CREATE TRIGGER puhkus_sequenced_trigger BEFORE INSERT OR UPDATE ON
> puhkus
>    FOR EACH ROW EXECUTE PROCEDURE puhkus_sequenced_pkey();

You can also use CREATE CONSTRAINT TRIGGER, which allows you to have
deferrable constraints. This is useful if statements within a
transaction may temporarily put the database in a state where it
violates the constraint: the constraint will be called at the end of
the transaction to make sure integrity is maintained.

http://www.postgresql.org/docs/8.2/interactive/sql-createconstraint.html

> create table puhkus (palgus date, plopp date);
>
> alter table puhkus add check
> (NOT EXISTS ( SELECT *
> FROM puhkus AS I1
> WHERE 1 < (SELECT COUNT(*)
> FROM puhkus AS I2
> WHERE doverlaps(i1.palgus, i1.plopp, i2.palgus, i2.plopp)
> ) ));
>
> but got error
>
> ERROR: cannot use subquery in check constraint

Right. As the error says, subqueries in CHECK constraints is not
implemented in PostgreSQL.


Michael Glaesemann
grzm seespotcode net



pgsql-general by date:

Previous
From: Michael Glaesemann
Date:
Subject: Re: Languages and Functions
Next
From: "Greg Sabino Mullane"
Date:
Subject: Re: feature suggestions