From: | Kenneth Tilton <ktilton(at)mcna(dot)net> |
---|---|
To: | pgsql-general(at)postgresql(dot)org |
Subject: | How can I modify a row in a function such that the caller sees it? |
Date: | 2012-03-27 13:26:22 |
Message-ID: | CAECCA8bVhaabj5QFB04fCefw0wzwHjKwdmdouNYfDg0FoN_aLg@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | 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
From | Date | Subject | |
---|---|---|---|
Next Message | Alban Hertroys | 2012-03-27 13:47:12 | Re: Facing error while restoring the database |
Previous Message | Akshay Joshi | 2012-03-27 13:12:51 | Re: Facing error while restoring the database |