Home > Blockchain >  How to detect the insertion of a new data?
How to detect the insertion of a new data?

Time:10-07

I would like to know if there is a way to detect each time there is a new data inserted in a data table so that I can update a chart in my application.

I use postgreSQL, node.js, vue.js for the framework and chart js for the display.

CodePudding user response:

Assuming that the source database table contains an ID column that is incremented by a SEQUENCE, you can repeatedly select new data as follows:

SELECT * from <table name> where ID > :lastSelectedID
ORDER BY ID ASC;

In case the source table contains a column that holds the insertion date/time (i.e. CREATED), the same could look as follows:

SELECT * from <table name> where CREATED > :lastSelectedCreated
ORDER BY CREATED ASC;;
  • Related