From 0099e083a14fa4770ee5df7f408b61e03d8bd294 Mon Sep 17 00:00:00 2001 From: nathannau Date: Wed, 9 Sep 2020 08:00:05 +0200 Subject: [PATCH 1/2] Update plsh.c Pass new values on trigger update (not only old value) --- plsh.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/plsh.c b/plsh.c index 78c2bbd..a5255a2 100644 --- a/plsh.c +++ b/plsh.c @@ -478,6 +478,7 @@ handler_internal(Oid function_oid, FunctionCallInfo fcinfo, bool execute) } if (TRIGGER_FIRED_FOR_ROW(trigdata->tg_event)) + { for (i = 0; i < tupdesc->natts; i++) { char * s; @@ -495,6 +496,28 @@ handler_internal(Oid function_oid, FunctionCallInfo fcinfo, bool execute) arguments[argc++] = s; } + if (TRIGGER_FIRED_BY_UPDATE(trigdata->tg_event)) + { + HeapTuple newtuple = trigdata->tg_newtuple; + for (i = 0; i < tupdesc->natts; i++) + { + char * s; + bool isnull; + Datum attr; + + attr = heap_getattr(newtuple, i + 1, tupdesc, &isnull); + if (isnull) + s = ""; + else + s = type_to_cstring(attr, TupleDescAttr(tupdesc, i)->atttypid); + + elog(DEBUG2, "arg %d is \"%s\" (type %u)", i, s, + TupleDescAttr(tupdesc, i)->atttypid); + + arguments[argc++] = s; + } + } + } /* since we can't alter the tuple anyway, set up a return tuple right now */ From a1047db07861b4d6b291f14875b06aae894c89ab Mon Sep 17 00:00:00 2001 From: nathannau Date: Wed, 9 Sep 2020 08:13:53 +0200 Subject: [PATCH 2/2] Update trigger.out --- test/expected/trigger.out | 2 ++ 1 file changed, 2 insertions(+) diff --git a/test/expected/trigger.out b/test/expected/trigger.out index 1daef69..aca9d81 100644 --- a/test/expected/trigger.out +++ b/test/expected/trigger.out @@ -73,6 +73,8 @@ PLSH_TG_WHEN=AFTER Arg is 'dummy2' Arg is '1' Arg is 'one' +Arg is '1' +Arg is 'oneone' PLSH_TG_LEVEL=ROW PLSH_TG_NAME=testtrigger2 PLSH_TG_OP=UPDATE