Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1WwXw8-0006Nf-6S for pgsql-hackers@arkaria.postgresql.org; Mon, 16 Jun 2014 14:31:04 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1WwXw7-0001bs-HH for pgsql-hackers@arkaria.postgresql.org; Mon, 16 Jun 2014 14:31:03 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1WwXw6-0001bi-Ff for pgsql-hackers@postgresql.org; Mon, 16 Jun 2014 14:31:02 +0000 Received: from raven.toroid.org ([178.63.84.200]) by magus.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1WwXw0-0005b1-7y for pgsql-hackers@postgresql.org; Mon, 16 Jun 2014 14:31:01 +0000 Received: from kea.toroid.org (unknown [10.9.8.10]) by raven.toroid.org (Postfix) with ESMTP id A4B17240C688; Mon, 16 Jun 2014 16:30:54 +0200 (CEST) Received: by kea.toroid.org (Postfix, from userid 1000) id E036D4E120B; Mon, 16 Jun 2014 20:00:53 +0530 (IST) Date: Mon, 16 Jun 2014 20:00:53 +0530 From: Abhijit Menon-Sen To: Haribabu Kommi Cc: David Johnston , pgsql-hackers@postgresql.org Subject: [REVIEW] Re: Re: BUG #9578: Undocumented behaviour for temp tables created inside query language (SQL) functions Message-ID: <20140616143053.GA13668@toroid.org> References: <20140315165011.20722.74795@wrigleys.postgresql.org> <1395027732507-5796262.post@n5.nabble.com> <1395033331936-5796272.post@n5.nabble.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Pg-Spam-Score: -1.9 (-) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-hackers Precedence: bulk Sender: pgsql-hackers-owner@postgresql.org (Cc: to pgsql-bugs dropped.) At 2014-03-17 18:24:55 +1100, kommi.haribabu@gmail.com wrote: > > *** a/doc/src/sgml/xfunc.sgml > --- b/doc/src/sgml/xfunc.sgml > *************** > *** 153,159 **** SELECT clean_emp(); > --- 153,186 ---- > (\) (assuming escape string syntax) in the body of > the function (see ). > > + > + > + Parsing mechanism of a function > > + > + function > + parsing mechanism > + I suggest "Catalog changes within functions" instead of the above title. > + > + The body of an SQL function is parsed as if it were a single - multi-part > + statement and thus uses a constant snapshot of the system catalogs for > + every sub-statement therein. Commands that alter the catalog will likely not > + work as expected. > + > + > + > + For example: Issuing "CREATE TEMP TABLE" within an SQL function will add > + the table to the catalog but subsequent statements in the same function will > + not see those additions and thus the temporary table will be invisible to them. > + > + > + > + Thus it is generally advised that PL/pgSQL be used, instead of > + SQL, when any catalog visibilities are required in the same function. > + > + I don't think that much text is warranted. I suggest something like the following condensed wording: The body of an SQL function is parsed as if it were a single multi-part statement, using a constant snapshot of the system catalogs. The effect of any commands that alter the catalogs (e.g. "CREATE TEMP TABLE") will therefore not be visible to subsequent commands in the function body. The recommended workaround is to use PL/PgSQL. Does that seem sensible to you? -- Abhijit -- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers