Changefeeds allow you to retrieve and sync changes from SurrealDB to external systems and platforms using the SHOW statement.
For updates to existing records, the shape of each mutation depends on how the changefeed was defined on the table. When you use INCLUDE ORIGINAL with CHANGEFEED, stored differences are reverse diffs: they describe the changes required to go from the record’s state after the write back to the state immediately before it.
For updates to existing records, the shape of each mutation depends on how the changefeed was defined on the table. When you use INCLUDE ORIGINAL with CHANGEFEED, stored differences are reverse diffs: they describe the changes required to go from the record’s state after the write back to the state immediately before it. See the DEFINE TABLE examples for sample responses with and without INCLUDE ORIGINAL.
Requirements
You must first
DEFINEa changefeed on either a table or a database.
Statement syntax
Example usage
Basic usage
The following expression shows usage of the SHOW statement.
Assuming the datetime above matches with the one when the changefeed was established, the response for both queries will be as follows.
Note the following when working with the versionstamps of a changefeed:
Changefeeds defined on tables are implemented via a single
CHANGEFEEDon the database level. As such,SHOW CHANGES FOR TABLE sometablewill only show versionstamps in sequential order ifsometableis the database's only table.The
versionstampoutput above is due to an extra two bytes needed for more detailed ordering needed in the FoundationDB distributed SurrealDB backend. To turn these versionstamps into a normal sequence of numbers, a right shift of sixteen bits (>> 16) can be used.A
SINCE <numbergreater than the current sequential number will return an empty array.SINCE <time>needs to be a datetime after which theCHANGEFEEDwas defined.
Versionstamps carry the following two guarantees:
Versionstamps monotonically increase.
Versionstamp format is universal across various backends.