I need to run some SQL scripts (which are basically SELECT queries) every time some new data enters the database.
When I say enters the database, I do not mean INSERT/UPDATE queries executed on an existing database/table(s), but rather every time a new database is created.
I am using PostgreSQL as my SQL DBMS.
I have tried many approaches but none of them suit my requirement -
- pgAgent/pg_cron - requires a time constraint to be specified. Can only be triggered periodically.
- SQL TRIGGER - can be applied only on a database (INSERT/UPDATE/DELETE trigger to check if a query has been executed on a database, i.e., assuming the database already exists)
I am yet to try the usage of a Procedural Language (PL/PgSQL, PL/PERL), but it would be nice if someone could point me in the right direction before I proceed.
TL;DR: I need to run a SQL script on a PostgreSQL installation every time a new database is created (on a given server).