Multiple parameters with the same name for functions.

Started by Gevik Babakhaniover 16 years ago4 messages
#1Gevik Babakhani
pgdev@xs4all.nl

Hi,

As I was working on my code generator app, I noticed that one is able to
create a function with multiple parameters with the same name. For example:

create or replace function func_test(id integer,id varchar, id
timestamp) returns void as
$$
begin
raise notice '%',id;
end;
$$
language plpgsql;

Is this a known behavior or a bug?

Regards,
Gevik.

#2Jaime Casanova
jcasanov@systemguards.com.ec
In reply to: Gevik Babakhani (#1)
Re: Multiple parameters with the same name for functions.

On Sun, Apr 26, 2009 at 3:32 PM, Gevik Babakhani <pgdev@xs4all.nl> wrote:

Hi,

As I was working on my code generator app, I noticed that one is able to
create a function with multiple parameters with the same name. For example:

you mean this http://www.postgresql.org/docs/current/static/xfunc-overload.html?

--
Atentamente,
Jaime Casanova
Soporte y capacitación de PostgreSQL
Asesoría y desarrollo de sistemas
Guayaquil - Ecuador
Cel. +59387171157

#3Gevik Babakhani
pgdev@xs4all.nl
In reply to: Jaime Casanova (#2)
Re: Multiple parameters with the same name for functions.

No. I meant: create function foo(PAR1 varchar, PAR1 int, PAR1 uuid).
Note PAR1

Jaime Casanova wrote:

Show quoted text

On Sun, Apr 26, 2009 at 3:32 PM, Gevik Babakhani <pgdev@xs4all.nl> wrote:

Hi,

As I was working on my code generator app, I noticed that one is able to
create a function with multiple parameters with the same name. For example:

you mean this http://www.postgresql.org/docs/current/static/xfunc-overload.html?

#4Tom Lane
tgl@sss.pgh.pa.us
In reply to: Gevik Babakhani (#1)
Re: Multiple parameters with the same name for functions.

Gevik Babakhani <pgdev@xs4all.nl> writes:

As I was working on my code generator app, I noticed that one is able to
create a function with multiple parameters with the same name.

I'm pretty sure this has come up before and we concluded that
prohibiting it in CREATE FUNCTION wasn't terribly exciting. For
instance there is no compelling reason I shouldn't be able to define

create function sum(addend int, addend int) returns ...

In the context of plpgsql specifically, it might make sense to
disallow it. I notice that plpgsql is pretty sloppy about other
cases of conflicting declarations:

regression=# create function foo() returns void as $$
regression$# declare
regression$# id int := 1;
regression$# id text := 'foo';
regression$# begin
regression$# raise notice '%', id;
regression$# end$$ language plpgsql;
ERROR: syntax error at or near "id"
LINE 4: id text := 'foo';
^
regression=#

OK, failure is expected, but "syntax error"?

regards, tom lane