On 15 April 2012 17:55, Pavel Stehule <pavel.steh...@gmail.com> wrote: > 2012/4/15 Brendan Jurd <dire...@gmail.com>: >> It turns out that in a PL/PgSQL function, you can DECLARE a variable >> using the same name as one of the function parameters. This has the >> effect of clobbering the parameter, for example: >> ... >> >> I would suggest that if the user DECLAREs a variable with the same >> name as a parameter, it is very evidently a programming error, and we >> should raise the same "duplicate declaration" error. I haven't yet >> looked at how difficult this would be to fix, but if there are no >> objections I would like to attempt a patch. >> > > I disagree - variables and parameters are in different namespace so > you can exactly identify variable and parameter. More - it is > compatibility break. >
They may technically be in different namespaces, but the fact that the declared variable quietly goes ahead and masks the parameter locally, seems like a recipe for unexpected consequences. It certainly was in my case, and I doubt I'm the first or the last to make that mistake. Under these conditions, you now have "foo" which refers to the variable, and "declare_clobber.foo" which refers to the parameter. Not exactly a model of clarity, and it's also quite easy to miss the part of the PL/PgSQL docs mentioning this notation. Perhaps it's a failure of imagination on my part, but I can't think of a legitimate reason for a programmer to deliberately use the same name to refer to a declared variable and a function parameter. What would be the benefit? Cheers, BJ -- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers