Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1U79TU-0004lQ-Ga for pgsql-sql@arkaria.postgresql.org; Sun, 17 Feb 2013 19:00:32 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.72) (envelope-from ) id 1U79TT-0007rh-RH for pgsql-sql@arkaria.postgresql.org; Sun, 17 Feb 2013 19:00:31 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1U79TS-0007rb-Ux for pgsql-sql@postgresql.org; Sun, 17 Feb 2013 19:00:31 +0000 Received: from mout.gmx.net ([212.227.17.21]) by magus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1U79TR-00068o-0r for pgsql-sql@postgresql.org; Sun, 17 Feb 2013 19:00:30 +0000 Received: from mailout-de.gmx.net ([10.1.76.17]) by mrigmx.server.lan (mrigmx002) with ESMTP (Nemesis) id 0M2rdY-1UzoI41E2Q-00siWC for ; Sun, 17 Feb 2013 20:00:22 +0100 Received: (qmail invoked by alias); 17 Feb 2013 18:58:04 -0000 Received: from mue-88-130-15-237.dsl.tropolys.de (EHLO [192.168.1.113]) [88.130.15.237] by mail.gmx.net (mp017) with SMTP; 17 Feb 2013 19:58:04 +0100 X-Authenticated: #14269776 X-Provags-ID: V01U2FsdGVkX19Nhop8S6pNAidqmjcqFM5kCg0wSEgYBEPomwvbQA YMUXG6utyniV/e Message-ID: <51212881.1040600@gmx.net> Date: Sun, 17 Feb 2013 19:59:13 +0100 From: Andreas User-Agent: Mozilla/5.0 (Windows NT 5.1; rv:17.0) Gecko/20130107 Thunderbird/17.0.2 MIME-Version: 1.0 To: pgsql-sql@postgresql.org CC: andreas@a-kretschmer.de Subject: Re: How to reject overlapping timespans? References: <51210D23.9070403@gmx.net> <1735216876.37617.1361125250332.JavaMail.open-xchange@ox.ims-firmen.de> In-Reply-To: <1735216876.37617.1361125250332.JavaMail.open-xchange@ox.ims-firmen.de> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Y-GMX-Trusted: 0 X-Pg-Spam-Score: -2.5 (--) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-sql Precedence: bulk Sender: pgsql-sql-owner@postgresql.org Am 17.02.2013 19:20, schrieb Andreas Kretschmer: > Andreas hat am 17. Februar 2013 um 18:02 geschrieben: >> I need to store data that has a valid timespan with start and enddate. >> >> objects ( id, name, ... ) >> object_data ( object_id referencs objects(id), startdate, enddate, ... ) >> >> nothing special, yet >> >> How can I have PG reject a data record where the new start- or enddate >> lies between the start- or enddate of another record regarding the same >> object_id? > With 9.2 you can use DATERANGE and exclusion constraints > > test=# create table maps(id int, duration daterange, exclude using gist(id with > =, duration with &&)); > NOTICE: CREATE TABLE / EXCLUDE will create implicit index > "maps_id_duration_excl" for table "maps" > CREATE TABLE > test=*# insert into maps values (1,'(2013-01-01,2013-01-10]'); > INSERT 0 1 > test=*# insert into maps values (1,'(2013-01-05,2013-01-15]'); > ERROR: conflicting key value violates exclusion constraint > "maps_id_duration_excl" > DETAIL: Key (id, duration)=(1, [2013-01-06,2013-01-16)) conflicts with existing > key (id, duration)=(1, [2013-01-02,2013-01-11)). > test=*# though I still have a 9.1.x as productive server so I'm afraid I have to find another way. Thanks, Andreas :) -- Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-sql