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: function param and declared variable of same name
Date: 2011-09-01 05:30:00
Message-ID: 4E5F1858.8040207@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 http-equiv="content-type" content="text/html; charset=ISO-8859-1"><style>body
p { margin-bottom: 0cm; margin-top: 0pt; } </style>
</head>
<body style="direction: ltr;"
bidimailui-detected-decoding-type="latin-charset" bgcolor="#ffffff"
text="#000000">
<p>Tested in 8.2 and 9.0.1</p>
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.<br>
The correct action, IMO, would be to raise an error.<br>
<br>
create or replace function test1(x int) returns int as<br>
$$<br>
declare x int;<br>
begin<br>
    return x;<br>
end;<br>
$$ language 'plpgsql';<br>
<br>
Thanks<br>
Sim<br>
</body>
</html>

Attachment Content-Type Size
unknown_filename text/html 885 bytes

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Guillaume Lelarge 2011-09-01 06:05:44 Re: ERD Tool
Previous Message John R Pierce 2011-09-01 04:48:26 Re: function on trigger