Re: function param and declared variable of same name

From: Sim Zacks <sim(at)compulab(dot)co(dot)il>
To: PostgreSQL general <pgsql-general(at)postgresql(dot)org>
Subject: Re: function param and declared variable of same name
Date: 2011-09-01 07:45:20
Message-ID: 4E5F3810.7000505@compulab.co.il
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html style="direction: ltr;">
<head>
<meta content="text/html; charset=UTF-8" http-equiv="Content-Type">
<style>body p { margin-bottom: 0cm; margin-top: 0pt; } </style>
</head>
<body style="direction: ltr;"
bidimailui-detected-decoding-type="UTF-8" bgcolor="#ffffff"
text="#000000">
On 09/01/2011 09:58 AM, Pavel Stehule wrote:
<blockquote
cite="mid:CAFj8pRBtVU4Ry5VJL6CRBzEOqbOA7se38aLORY6ooPAnNa0eUg(at)mail(dot)gmail(dot)com"
type="cite">
<pre wrap="">2011/9/1 Sim Zacks <a class="moz-txt-link-rfc2396E" href="mailto:sim(at)compulab(dot)co(dot)il">&lt;sim(at)compulab(dot)co(dot)il&gt;</a>:
</pre>
<blockquote type="cite">
<pre wrap="">Tested in 8.2 and 9.0.1

In plpgsql, if you have a function parameter and a variable of the same
name, it ignores the value passed in and initializes the variable to null.
The correct action, IMO, would be to raise an error.
</pre>
</blockquote>
<pre wrap="">
You can access params via $n conventions. functions params and
functions variables are not in same space, so it should not be a
error. What behave is in PL/SQL? There should be problem with backward
compatibility when we change it.

Regards

Pavel Stehule</pre>
</blockquote>
While you _can_ access the variable using the $n convention, it is
an obvious mistake in the function definition. It may break existing
functions, but all of those functions have bugs in them that will
then be caught. Can you think of any valid case for passing in a
variable and having the variable name refer to something else? <br>
<br>
Sim<br>
</body>
</html>

Attachment Content-Type Size
unknown_filename text/html 1.6 KB

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Sim Zacks 2011-09-01 08:47:24 md5 of table
Previous Message hubert depesz lubaczewski 2011-09-01 06:05:51 Re: [GENERAL] pg_upgrade problem