Received: from makus.postgresql.org (makus.postgresql.org [98.129.198.125]) by mail.postgresql.org (Postfix) with ESMTP id 4FA92930E1E for ; Fri, 3 Aug 2012 16:51:12 -0300 (ADT) Received: from eastrmfepo202.cox.net ([68.230.241.217]) by makus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1SxNtr-00008N-UF for pgsql-sql@postgresql.org; Fri, 03 Aug 2012 19:51:11 +0000 Received: from eastrmimpo306.cox.net ([68.230.241.238]) by eastrmfepo202.cox.net (InterMail vM.8.01.04.00 201-2260-137-20101110) with ESMTP id <20120803195054.KYVQ1165.eastrmfepo202.cox.net@eastrmimpo306.cox.net> for ; Fri, 3 Aug 2012 15:50:54 -0400 Received: from slacker.ja10629.home ([68.106.109.147]) by eastrmimpo306.cox.net with bizsmtp id iKqt1j00V3Ar1Vg02KqtTK; Fri, 03 Aug 2012 15:50:53 -0400 X-CT-Class: Clean X-CT-Score: 0.00 X-CT-RefID: str=0001.0A020204.501C2B9D.00E7,ss=1,re=0.000,fgs=0 X-CT-Spam: 0 X-Authority-Analysis: v=1.1 cv=nyDZ0P/OMruea3Zhuq/VoJ7MUk+vKhFfsSw+I1YbgRg= c=1 sm=1 a=z1TLwsU0kBEA:10 a=jx93n2yizJUA:10 a=PjkiJtDTOQ4A:10 a=ZcFhQy0-F_sA:10 a=kj9zAlcOel0A:10 a=sXZhTwfwSKhiTs9RzZXpNQ==:17 a=epTmVMiNAAAA:8 a=5gDpCBLMYBHDOK40gAQA:9 a=CjuIK1q_8ugA:10 a=DPBh0lOsg_UA:10 a=sXZhTwfwSKhiTs9RzZXpNQ==:117 X-CM-Score: 0.00 Authentication-Results: cox.net; none Received: from wcuddy by slacker.ja10629.home with local (Exim 4.72) (envelope-from ) id 1SxNtd-000681-Cf for pgsql-sql@postgresql.org; Fri, 03 Aug 2012 15:50:53 -0400 Date: Fri, 3 Aug 2012 15:50:53 -0400 From: Wayne Cuddy To: PostgreSQL Subject: Re: can this be done with a check expression? Message-ID: <20120803195053.GA16371@slacker.ja10629.home> Mail-Followup-To: PostgreSQL References: <20120802231043.GA16173@slacker.ja10629.home> <88520F99-849D-438C-9CCD-F80700636A2A@excoventures.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <88520F99-849D-438C-9CCD-F80700636A2A@excoventures.com> User-Agent: Mutt/1.4.2.3i X-Pg-Spam-Score: -1.9 (-) X-Archive-Number: 201208/6 X-Sequence-Number: 36777 Thanks for the input. I don't insert into this table that often so I'll just prevent overlaps at the application level since I'm running 9.0.X and not really in a position to upgrade right now. Thanks again, Wayne On Fri, Aug 03, 2012 at 11:50:13AM -0400, Jonathan S. Katz wrote: > On Aug 2, 2012, at 7:10 PM, Wayne Cuddy wrote: > > > I have a table with 3 columns: > > > > name text > > start_id integer > > end_id integer > > > > start_id and end_id are ranges which must not overlap but can have gaps > > between them. Is it possible to formulate a table check constraint that > > can verify that either id does not fall within an existing range at > > insert time? IE prevent overlaps during insert? > > > > Thanks, > > Wayne > > So this answer will not help you for the here-and-now, but Postgres 9.2 is going to be released in the near future (though the beta is available) and contains "range types" which have check constraints on them: > > http://www.postgresql.org/docs/9.2/static/rangetypes.html#RANGETYPES-CONSTRAINT > > You could formulate a check constraint right now to do the equivalent, albeit it will involve a lot of conditions. > > Jonathan