Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pass new values on trigger update (not only old value) #18

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions plsh.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 */
Expand Down
2 changes: 2 additions & 0 deletions test/expected/trigger.out
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down