Search Postgresql Archives

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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux