How can I modify a row in a function such that the caller sees it?

Поиск
Список
Период
Сортировка
От Kenneth Tilton
Тема How can I modify a row in a function such that the caller sees it?
Дата
Msg-id CAECCA8bVhaabj5QFB04fCefw0wzwHjKwdmdouNYfDg0FoN_aLg@mail.gmail.com
обсуждение исходный текст
Список pgsql-general
Bit of a nooby Q, tho I have researched this quite a bit and found nothing and it seems simple: I just want to modify a row in a plpgsql function such that the change can be seen by the caller. 

The functions happen to be called in a before trigger, to finish initializing the row. The functions are named in a column of the new row, so they are effectively callbacks.

The closest I have come was an error saying the function returned nine columns, which is great because the row has nine columns. :)

Somewhat condensed (I know, I know <g>) Here is the calling trigger function:

CREATE OR REPLACE FUNCTION dcm.biz_proc_init()
  RETURNS trigger AS
$BODY$
  
declare
   bpnew dcm.biz_proc;
begin
   if NEW.timing_initializer is not null then
       execute 'select ' || NEW.timing_initializer || '($1)'
                 using NEW
                 into bpnew;
       return bpnew;
   else
       return NEW;
   end if;
end;
$BODY$
  LANGUAGE plpgsql VOLATILE
  COST 100;

Here is a callback:

CREATE OR REPLACE FUNCTION dcm.test_bp_init(bp dcm.biz_proc)
  RETURNS dcm.biz_proc AS
$BODY$
  
declare
begin
   bp.max_duration_time = now() + interval '30 days';
   return bp;
end;
$BODY$
  LANGUAGE plpgsql VOLATILE
  COST 100;

If the above looks OK I will carve out an actual disclosable pile of SQL to recreate the problem, but this seems like a trivial thing so I am hoping I just have missed the right bit of documentation of something straightforward.

-ken

В списке pgsql-general по дате отправления:

Предыдущее
От: Akshay Joshi
Дата:
Сообщение: Re: Facing error while restoring the database
Следующее
От: Alban Hertroys
Дата:
Сообщение: Re: Facing error while restoring the database