Received: from magus.postgresql.org (magus.postgresql.org [87.238.57.229]) by mail.postgresql.org (Postfix) with ESMTP id 9F1421E62E85 for ; Wed, 25 Apr 2012 13:23:33 -0300 (ADT) Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1SN506-0001Xf-E3 for pgsql-bugs@postgresql.org; Wed, 25 Apr 2012 16:23:32 +0000 Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.2/8.14.2) with ESMTP id q3PGNFah007396; Wed, 25 Apr 2012 12:23:15 -0400 (EDT) To: Greg Stark cc: Kevin Grittner , atrigent@ccs.neu.edu, pgsql-bugs@postgresql.org Subject: Re: BUG #6612: Functions can be called inside CHECK statements In-reply-to: References: <4F97CCB80200002500047332@gw.wicourts.gov> Comments: In-reply-to Greg Stark message dated "Wed, 25 Apr 2012 16:48:45 +0100" Date: Wed, 25 Apr 2012 12:23:15 -0400 Message-ID: <7395.1335370995@sss.pgh.pa.us> From: Tom Lane X-Pg-Spam-Score: -1.9 (-) X-Archive-Number: 201204/145 X-Sequence-Number: 32896 Greg Stark writes: > On Wed, Apr 25, 2012 at 4:06 PM, Kevin Grittner > wrote: >> A CHECK constraint using a volatile function is potentially valid >> and useful, IMO. > Hm. I suppose it depends on what you think a constraint is. I had > always thought it was a guarantee that all the data in the table would > meet that constraint. Not just a procedural definition for something > to do at certain points in time. Well, it's a guarantee that the expression evaluated to "true" at the time of insertion or update of every row. If you confine your attention to immutable expressions then you can presume that the expression is true for every row in the table at any time; but I'm with Kevin that there are reasonable use-cases that don't fit into that. > Hm, but this does raise the question of whether they're the right > thing to be basing the partitioning constraint exclusion code on. As long as we only consider expressions that are immutable as usable partition constraints, that's not a problem. > I'll > speculate without checking again that we check the immutability of the > constraint before using it in constraint exclusion but that seems a > ad-hoc. We do, and I don't see why that's ad-hoc. In general the planner has to check the volatility status of any expression it's going to try to reason about. regards, tom lane