Steven Plummer wrote:
> I have a table that has an integer and a int8range.
> What I want is to add a constraint that stops anyone adding
Maybe you want an exclusion constraint:
http://www.postgresql.org/docs/9.0/static/ddl-constraints.html#DDL-CONSTRAINTS-EXCLUSION
For example:
CREATE EXTENSION btree_gist ;
CREATE TABLE t1 (c1 INT NOT NULL,
c2 int8range NOT NULL,
EXCLUDE USING gist (c1 WITH =, c2 WITH &&));
INSERT INTO t1 VALUES (1, '[1,100]');
Now try to insert an overlapping row:
INSERT INTO t1 VALUES (1, '[51,150]');
-Kevin