Search Postgresql Archives

Re: Range constraint with unique index

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

 



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


-- 
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