Search Postgresql Archives

Re: Need help writing exclusion constraint

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Sat, 2011-01-15 at 15:07 -0500, Daniel Popowich wrote:
> Constraint expressions can only be simple boolean expressions, so can
> refer only to the column(s) of the current row you're
> inserting/updating, 

Exclusion Constraints are a new feature in 9.0:

http://www.postgresql.org/docs/9.0/static/ddl-constraints.html#DDL-CONSTRAINTS-EXCLUSION
http://www.postgresql.org/docs/9.0/static/sql-createtable.html#SQL-CREATETABLE-EXCLUDE

They allow you to constrain across rows, much like UNIQUE (in fact, the
constraints that can be expressed by an exclusion constraint are a
superset of the constraints that can be expressed by UNIQUE).


> so to refer to other records (which you'll need to
> do to compare destination_ids) you need to create a
> function...something along the lines of this:
> 

...

>     ALTER TABLE event ADD CONSTRAINT event_overlap
>              CHECK(overlap_at_dest(destination_id, starts, ends));

As Tomas said, that's an unsafe thing to do. I do not recommend using a
table-reading function in a check constraint.

Regards,
	Jeff Davis



-- 
Sent via pgsql-general mailing list (pgsql-general@xxxxxxxxxxxxxx)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux