Обсуждение: Question about passing User defined types to functions

Поиск
Список
Период
Сортировка

Question about passing User defined types to functions

От
"David Durst"
Дата:
is there a example on how to pass user defined types into
a function??

What I am looking for is something of this nature.

CREATE TYPE dumby_type AS (dumby_id int4, dumby_name text);

create function kick_dumby(dumby dumby_type) returns INTEGER AS '
DECLARE somenumber integer;
BEGIN return 1;
END;
' language 'plpgsql';


Is there some way of doing this, because the above doesn't work.




Re: Question about passing User defined types to functions

От
Christoph Haller
Дата:
>
> CREATE TYPE dumby_type AS (dumby_id int4, dumby_name text);
>
> create function kick_dumby(dumby dumby_type) returns INTEGER AS '
> DECLARE
>   somenumber integer;
> BEGIN
>   return 1;
> END;
> ' language 'plpgsql';
>
>
> Is there some way of doing this, because the above doesn't work.
>
After having a look into the documentation on CREATE TYPE
I would say the statement looks very wrong. But I haven't done
any user defined type so far, so I can't be of any help in this case.
The CREATE FUNCTION statement is not considered to accept
parameter names within the parameter list.
So use
create function kick_dumby(dumby_type) returns INTEGER AS '
DECLAREdumby ALIAS FOR $1;
...

Regards, Christoph



Re: Question about passing User defined types to functions

От
Tom Lane
Дата:
"David Durst" <ddurst@larubber.com> writes:
> CREATE TYPE dumby_type AS (dumby_id int4, dumby_name text);

> create function kick_dumby(dumby dumby_type) returns INTEGER AS '

Should be

create function kick_dumby(dumby_type) returns INTEGER AS '...
        regards, tom lane