Sample Header Ad - 728x90

PostgreSQL via plpython3u trigger - nrows() returns 0 instead of 1

0 votes
0 answers
20 views
Given the following code, when executed, the notify_date is updated as expected, but nrows() returns 0. Per the documentation: nrows() Returns the number of rows processed by the command. Note that this is not necessarily the same as the number of rows returned. For example, an UPDATE command will set this value but won't return any rows (unless RETURNING is used). This plan is in the global data: resetTargetNotifyDate = plpy.prepare(""" UPDATE target_tbl SET notify_date = null WHERE expression like '%' || $1 || '%' """, ['text'] ) funcs['resetTargetNotifyDate'] = resetTargetNotifyDate This is the trigger: create or replace function code_change() returns trigger language plpython3u AS $$ """ If code-group = 'Swap' then: Reset notify_date for all targets where expression contains 'Swap:' + code """ if not "trade" in GD: plpy.execute("select define_trade_globals()") logger = GD['generic']['logger'] trPlan = GD['trade']['funcs'] cdRow = TD['new'] if TD['event'] not in ['UPDATE'] or TD['when'] != 'BEFORE': plpy.error(f"Bad event or timing for trigger .") if cdRow['code_group'] == 'Swap': currUser = plpy.execute("select current_user")["current_user"] rslt = plpy.execute(trPlan['resetTargetNotifyDate'], [f"Swap:{cdRow['code']}"]) updCnt = rslt.nrows() logger.info(f"CdChg_b: Event '{TD['event']}', User '{currUser}', Swap for '{cdRow['code']}' caused {updCnt} notify_date resets") return "MODIFY" $$ ; Log: 2024-09-19 12:49:15.886: INFO : plpy.Stocks : CdChg_b: Event 'UPDATE', User 'dba', Swap for 'NMFC-ARR' caused 0 notify_date resets I cannot figure out why I get 0 when 1 row is updated.
Asked by Crashmeister (161 rep)
Sep 19, 2024, 04:52 PM