Home > other >  Checking new row is inserted in table database and run some script
Checking new row is inserted in table database and run some script

Time:02-10

I want to send some notification to android app when new row is inserted in table database, but I'm having trouble to check if there is new row inserted or not.

Is there any function or query to check if new row inserted in table? or some logic to acquire that.

CodePudding user response:

It depends on the database you are using. For example in MySQL you can query the table information_schema.tables to get the latest update time. https://dev.mysql.com/doc/refman/8.0/en/information-schema-tables-table.html

For postgres

Check if track commit timestamp is on

show track_commit_timestamp;

If it's off, set it to on in your postgresql.conf file and restart postgres.

Post that run the following to track the latest updates in your table

SELECT pg_xact_commit_timestamp(xmin), * FROM YOUR_TABLE_NAME;
  • Related