Обсуждение: new and old as parameter in a function

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

new and old as parameter in a function

От
"Riccardo G. Facchini"
Дата:
Hi.

I'm having some trouble, and I would like to receive some input by the
pg community...

I would like to write a failry complex PLPGSQL trigger that calls a
secondary function. The trigger calls the function with the NEW record
that returns a variable of type RECORD whith the NEW variable modified
accordingly to a series of actions.

By Reading the documentation, I understand that I can write a PLPGSQL
function that receives a parameter of type RECORD, and returns a
parameter of type RECORD, and that this function is callable from a
Trigger.

But:

I haven't been able to write what's expressed above...

is there somebody that can provide some help and/or some examples?

thanks in advance,



=====
Riccardo G. Facchini


Re: new and old as parameter in a function

От
Tom Lane
Дата:
"Riccardo G. Facchini" <abief_ag_-postgresql@yahoo.com> writes:
> By Reading the documentation, I understand that I can write a PLPGSQL
> function that receives a parameter of type RECORD,

You misread it --- that's not presently supported.

regression=# create function foo(record) returns int as '
regression'# begin
regression'#   return $1.f1;
regression'# end' language plpgsql;
ERROR:  plpgsql functions cannot take type record

However you can make a plpgsql function that accepts a parameter of a
specific (named) rowtype:

regression=# create table fooey(f1 int, f2 text);
CREATE TABLE
regression=# create function foo(fooey) returns int as '
regression'# begin
regression'#   return $1.f1;
regression'# end' language plpgsql;
CREATE FUNCTION
        regards, tom lane