Database Reference
In-Depth Information
CREATE TRIGGER'
SD[args] = logfunc
SD['env_plan'] = plpy.prepare("""
select clock_timestamp(),
txid_current(),
current_user,
current_database()""", [])
logfunc = SD[args]
env_info_row =
plpy.execute(SD['env_plan'])[0]
import json
log_msg = json.dumps(
{'txid' : env_info_row['txid_current'],
'time' :
env_info_row['clock_timestamp'],
'user' : env_info_row['current_user'],
'db' :
env_info_row['current_database'],
'table' : '%s.%s' % (TD['table_name'],
TD['table_schema']),
'event' : TD['event'],
'old' : TD['old'],
'new' : TD['new'],
}
)
logfunc(log_msg)
$$ LANGUAGE plpythonu;
First, this trigger checks if it already has a logger function defined and cached in the
function's local dictionary SD[] . As the same trigger may be used with many differ-
ent log destinations, the log function is stored under the key constructed as a Python
tuple from the trigger function arguments in the CREATE TRIGGER statement. We
can not use the TD["args"] list directly as a key, as Python dictionary keys have
to be immutable, which a list is not, but a tuple is.
Search WWH ::




Custom Search