After a lot of research, I found 3 queries that seem to answer my problem.
Any correction is welcome, SQL is not what I know best ...
The replication interval is defined by 2 TIMESTAMP WITHOUT TIME ZONE, because the driver I use is the one provided by the UNO API (OpenOffice / LibreOffice) and the getter/setter (getTimestamp/setTimestamp) does not manage TIMESTAMP WITH TIME ZONE, respectively timestart
and timestop
.
rowstart
: is the column declared as TIMESTAMP GENERATED ALWAYS AS ROW START.
rowend
: is the column declared as TIMESTAMP GENERATED ALWAYS AS ROW END.
customerid
: is the primary key to the customer table.
To find the records that have been updated:
SELECT current.customerid FROM customer FOR SYSTEM_TIME AS OF timestop + SESSION_TIMEZONE() AS current
INNER JOIN customer FOR SYSTEM_TIME FROM timestart + SESSION_TIMEZONE() TO timestop + SESSION_TIMEZONE() AS previous
ON current.customerid = previous.customerid AND current.rowstart = previous.rowend;
To find the records that have been inserted:
SELECT current.customerid FROM customer FOR SYSTEM_TIME AS OF timestop + SESSION_TIMEZONE() current
LEFT JOIN customer FOR SYSTEM_TIME AS OF timestart + SESSION_TIMEZONE() previous
ON current.customerid = previous.customerid WHERE previous.customerid IS NULL;
To find the records that have been deleted:
SELECT previous.customerid FROM customer FOR SYSTEM_TIME AS OF timestart + SESSION_TIMEZONE() previous
LEFT JOIN customer FOR SYSTEM_TIME AS OF timestop + SESSION_TIMEZONE() current
ON previous.customerid = current.customerid WHERE current.customerid IS NULL;
I do not know if the use of DATABASE_TIMEZONE instead of SESSION_TIMEZONE would be more judicious, free to who wants to confirm ...
I did not have time to test massively, but it works quickly even with a lot of record.
Et voila...
Edit: I just noticed that it is important to use the version hsqldb 2.5.1 because I did not manage to have a correct operation under 2.5.0 ...