pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Andreas Kretschmer <akretschmer@spamfence.net>
To: pgsql-sql@postgresql.org
Subject: Re: can this be done with a check expression?
Date: Fri, 3 Aug 2012 07:40:17 +0200
Message-ID: <20120803054016.GA7909@tux> (raw)
In-Reply-To: <29693.1343949814@sss.pgh.pa.us>
References: <20120802231043.GA16173@slacker.ja10629.home>
	<29693.1343949814@sss.pgh.pa.us>

Tom Lane <tgl@sss.pgh.pa.us> wrote:

> Wayne Cuddy <lists-pgsql@useunix.net> writes:
> A less bogus way of doing things is to use an EXCLUDE constraint,
> although that will restrict you to be running PG 9.0 or newer.  You
> also need some way of representing the ranges as indexable objects.
> In 9.0 or 9.1, probably the best way is to use contrib/seg/ to
> represent the ranges as line segments.  9.2 will have a cleaner
> solution, ie range types.

Simple example for 9.2:

test=# create table foo (name text, id_range int4range, exclude using gist(name with =, id_range with &&));
NOTICE:  CREATE TABLE / EXCLUDE will create implicit index "foo_name_id_range_excl" for table "foo"
CREATE TABLE
Time: 40,273 ms
test=*# insert into foo values ('name1', '[1,9)');
INSERT 0 1
Time: 0,660 ms
test=*# insert into foo values ('name1', '[10,19)');
INSERT 0 1
Time: 0,313 ms
test=*# insert into foo values ('name1', '[5,15)');
ERROR:  conflicting key value violates exclusion constraint "foo_name_id_range_excl"
DETAIL:  Key (name, id_range)=(name1, [5,15)) conflicts with existing key (name, id_range)=(name1, [1,9)).
test=!#


Great feature! Thx to all developers behing PG!



Andreas
-- 
Really, I'm not out to destroy Microsoft. That will just be a completely
unintentional side effect.                              (Linus Torvalds)
"If I was god, I would recompile penguin with --enable-fly."   (unknown)
Kaufbach, Saxony, Germany, Europe.              N 51.05082°, E 13.56889°



view thread (7+ messages)  latest in thread

Message-ID: <20120803054016.GA7909@tux>
Permalink:  ../20120803054016.GA7909@tux/
Also on:    postgresql.org/message-id/20120803054016.GA7909@tux

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: akretschmer@spamfence.net
  Subject: Re: can this be done with a check expression?
  In-Reply-To: <20120803054016.GA7909@tux>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox