Received: from makus.postgresql.org (makus.postgresql.org [98.129.198.125]) by mail.postgresql.org (Postfix) with ESMTP id 619E6930E1E for ; Fri, 3 Aug 2012 02:40:35 -0300 (ADT) Received: from mailout02.ims-firmen.de ([213.174.32.97]) by makus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1SxAcj-0003VQ-68 for pgsql-sql@postgresql.org; Fri, 03 Aug 2012 05:40:35 +0000 Received: from mailin03.ims-firmen.de ([192.168.1.143]) by mailout02.ims-firmen.de with esmtp (envelope-from ) id 1SxAcT-0002y1-lI for pgsql-sql@postgresql.org; Fri, 03 Aug 2012 07:40:17 +0200 Received: from [87.170.163.173] (helo=a-kretschmer.de) by mailin03.ims-firmen.de with esmtpsa (TLSv1:AES256-SHA:256) (envelope-from ) id 1SxAcT-00032c-7x for pgsql-sql@postgresql.org; Fri, 03 Aug 2012 07:40:17 +0200 Received: from kretschmer by a-kretschmer.de with local (Exim 4.69) (envelope-from ) id 1SxAcT-0002DO-0b for pgsql-sql@postgresql.org; Fri, 03 Aug 2012 07:40:17 +0200 Date: Fri, 3 Aug 2012 07:40:17 +0200 From: Andreas Kretschmer To: pgsql-sql@postgresql.org Subject: Re: can this be done with a check expression? Message-ID: <20120803054016.GA7909@tux> References: <20120802231043.GA16173@slacker.ja10629.home> <29693.1343949814@sss.pgh.pa.us> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <29693.1343949814@sss.pgh.pa.us> X-OS: Debian/GNU Linux - weil ich es mir Wert bin! X-GPG-Fingerprint: EE16 3C01 7B9C 10F7 2C8B 3B86 4DB3 D9EE 7F45 84DA X-Message-Flag: "Windows" is not the answer. "Windows" is the question and the answer is "no"! X-Lugdd: Gerd Kube X-Info: My name is root. Just root. And I am licensed to kill -9 User-Agent: Mutt/1.5.18 (2008-05-17) X-Pg-Spam-Score: -1.9 (-) X-Archive-Number: 201208/4 X-Sequence-Number: 36775 Tom Lane wrote: > Wayne Cuddy 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°