Re: Best way to prevent overlapping dates

From: Michael Glaesemann <grzm(at)seespotcode(dot)net>
To: Andrus <kobruleht2(at)hot(dot)ee>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Best way to prevent overlapping dates
Date: 2007-05-29 15:59:33
Message-ID: F6BA8F44-EE0D-4007-96C5-8B5A3D98CA00@seespotcode.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Greg Sabino Mullane 2007-05-29 16:09:50 Re: feature suggestions
Previous Message Michael Glaesemann 2007-05-29 15:56:26 Re: Languages and Functions