This TRIGGER function calls PosgreSQL's NOTIFY
command with a JSON payload. You can listen for these calls and then send the JSON payload to a message queue (like AMQP/RabbitMQ) or trigger other actions.
Create the trigger with notify_trigger.sql.
When declaring the trigger, supply the column names you want the JSON payload to contain as arguments to the function (see create_triggers.sql)
The payload returns a JSON object:
Magic words:
psql -U postgres
Some interesting flags (to see all, use -h
or --help
depending on your psql version):
-E
: will describe the underlaying queries of the\
commands (cool for learning!)-l
: psql will list all databases and then exit (useful if the user you connect with doesn't has a default database, like at AWS RDS)