dbTalk Databases Forums  

[BUGS] BUG #1956: Plpgsql top-level DECLARE does not share scope with CREATE FUNCTION

mailing.database.pgsql-bugs mailing.database.pgsql-bugs


Discuss [BUGS] BUG #1956: Plpgsql top-level DECLARE does not share scope with CREATE FUNCTION in the mailing.database.pgsql-bugs forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Karl O. Pinc
 
Posts: n/a

Default [BUGS] BUG #1956: Plpgsql top-level DECLARE does not share scope with CREATE FUNCTION - 10-12-2005 , 12:28 PM







The following bug has been logged online:

Bug reference: 1956
Logged by: Karl O. Pinc
Email address: kop (AT) meme (DOT) com
PostgreSQL version: 8.0.3
Operating system: Linux
Description: Plpgsql top-level DECLARE does not share scope with
CREATE FUNCTION
Details:

Depending on how you want to look at it, this is not really a bug. It does
produce odd results though.

The ALIASes for function parameters that get created as part of the plpgsql
CREATE FUNCTION do not share scope (namespace?) with the top-level DECLARE
of the function. As a result, you inadvertently make your function
arguments 'disappear' by "re-declaring" them in the top-level DECLARE. I
haven't put any deep thought into this, but offhand this 'feature' seems to
have no utility but does have the ability to cause problems. Hence, this
report.

It would be nice if somebody who has deep thoughts on this would think
them.

I would expect the below to produce an error when creating foo(int). The
error would complain about trying to declare the same thing with two
different types. Instead we see the result below.

create function foo (arg int)
returns int
language plpgsql
as $$
declare
arg text;
begin
return bar(arg);
end;
$$;

create function bar (arg int)
returns int
language plpgsql
as $$
begin
return arg + 1;
end;
$$;

babase=# select foo(1);
ERROR: function bar(text) does not exist
HINT: No function matches the given name and argument types. You may need
to add explicit type casts.
CONTEXT: SQL statement "SELECT bar( $1 )"
PL/pgSQL function "foo" line 4 at return

Regards,
Karl O. Pinc

---------------------------(end of broadcast)---------------------------
TIP 1: if posting/reading through Usenet, please send an appropriate
subscribe-nomail command to majordomo (AT) postgresql (DOT) org so that your
message can get through to the mailing list cleanly

Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.