PostgreSQL, How to include foreign key values into record on trigger?

Viewed 22

I have found example trigger function from here function from here. Which allows me to notify as JSON:

-- Build the payload
payload := json_build_object(
    'timestamp',CURRENT_TIMESTAMP,
    'action',LOWER(TG_OP),
    'schema',TG_TABLE_SCHEMA,
    'identity',TG_TABLE_NAME,
    'record',row_to_json(rec),
    'old',row_to_json(dat));

-- Notify the channel
PERFORM pg_notify('channel',payload);

I have assigned this function to multiple tables. One table has foreign key. When TG_TABLE_NAME is equal to simplemodel it has foreign key for simpleparent. How can I include simpleparents data into records fields?

0 Answers
Related