Received: from maia.hub.org (maia-2.hub.org [200.46.204.251]) by mail.postgresql.org (Postfix) with ESMTP id 6AB05B5DC29 for ; Wed, 21 Sep 2011 21:01:03 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.251]) (amavisd-maia, port 10024) with ESMTP id 45892-03 for ; Thu, 22 Sep 2011 00:00:52 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.8.0-rc2 Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by mail.postgresql.org (Postfix) with ESMTP id 5B882B5DC1A for ; Wed, 21 Sep 2011 21:00:51 -0300 (ADT) 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 p8M00oYL003451; Wed, 21 Sep 2011 20:00:50 -0400 (EDT) To: "David Johnston" cc: "'Samuel Gendler'" , pgsql-sql@postgresql.org Subject: Re: ambiguous local variable name in 9.0 proc In-reply-to: <00c301cc78b9$0ca38e30$25eaaa90$@yahoo.com> References: <00c301cc78b9$0ca38e30$25eaaa90$@yahoo.com> Comments: In-reply-to "David Johnston" message dated "Wed, 21 Sep 2011 19:49:05 -0400" Date: Wed, 21 Sep 2011 20:00:50 -0400 Message-ID: <3450.1316649650@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-2.404 tagged_above=-5 required=5 tests=BAYES_00=-1.9, RP_MATCHES_RCVD=-0.504 X-Spam-Level: X-Archive-Number: 201109/63 X-Sequence-Number: 35863 "David Johnston" writes: > On Behalf Of Samuel Gendler > I'm happy to modify the proc definition, except that I am unsure how to do > so other than to rename the variable, which is my least favourite way to do > that. I'd far rather qualify the name somehow, so that it knows that I am > refering to a local variable, if at all possible. Suggestions? > Not tested but I think all local variables are implicitly scoped to the > function name so you should be able to do the following: > WHERE reporting_mgmt.aggregate_timescales_impl.tbl_schema = e.tbl_schema More accurately: you can qualify a local variable's name with the label attached to the block in which it's declared; or with the function's name if the variable is a function parameter. See the fine manual: http://www.postgresql.org/docs/9.0/static/plpgsql-structure.html > I believe there is some way to define the function so that it does not throw > that particular error; it would be up to you make sure that the ambiguity is > being resolved correctly (which it should in this particular case). Yes, see variable_conflict in http://www.postgresql.org/docs/9.0/static/plpgsql-implementation.html I wouldn't really recommend turning off the conflict detection, though. We put it in because of the number of hours people had wasted on unrecognized conflicts. regards, tom lane