Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1UwhYO-00081u-FX for pgsql-general@arkaria.postgresql.org; Tue, 09 Jul 2013 23:42:40 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1UwhYN-0004ow-Dt for pgsql-general@arkaria.postgresql.org; Tue, 09 Jul 2013 23:42:39 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1UwhYM-0004oJ-47 for pgsql-general@postgresql.org; Tue, 09 Jul 2013 23:42:38 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1UwhYJ-0002rP-3T for pgsql-general@postgresql.org; Tue, 09 Jul 2013 23:42:37 +0000 Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.5/8.14.5) with ESMTP id r69NgYi4007166; Tue, 9 Jul 2013 19:42:34 -0400 (EDT) From: Tom Lane To: Joe Van Dyk cc: "pgsql-general@postgresql.org" Subject: Re: plpgsql plan caching allowing invalid data to enter table? In-reply-to: References: Comments: In-reply-to Joe Van Dyk message dated "Tue, 09 Jul 2013 16:05:27 -0700" Date: Tue, 09 Jul 2013 19:42:33 -0400 Message-ID: <7165.1373413353@sss.pgh.pa.us> X-Pg-Spam-Score: -2.2 (--) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-general Precedence: bulk Sender: pgsql-general-owner@postgresql.org Joe Van Dyk writes: > It's looking like I can use a plpgsql function to insert data into a table > that violates a domain constraint. Is this a known problem? I think it's not really plpgsql's fault but domain_in's --- there's no provision for flushing the latter's cached info about how to check domain constraints. (You can't see this in simple commands because the cache only lives as long as the statement, but I think plpgsql is letting it get put into the function's definitional memory context, which will pretty much survive for the whole session if you don't redefine the function.) We could ameliorate this case and probably improve performance as well by keeping domain check info in the typcache rather than using ad-hoc storage for it. However, I think it's a mistake to imagine that there's ever going to be a bulletproof guarantee that you can whack domain constraints around in a live database and not have any risk of some data going unchecked. As a couple of examples: * suppose you do the ALTER DOMAIN, and commit it at an instant where the plpgsql function is actively executing and has a live variable value of that domain type. Nothing is going to make the constraint change apply retroactively to that variable. * suppose you don't do an ALTER DOMAIN at all, but just change the behavior of a function that's used in a check constraint. regards, tom lane -- Sent via pgsql-general mailing list (pgsql-general@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-general