You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
CREATE OR REPLACE TRIGGER notify_items_change_insert
247
+
AFTER INSERT ON pgstac.items
248
+
REFERENCING NEW TABLE AS data
249
+
FOR EACH STATEMENT EXECUTE FUNCTION notify_items_change_func()
250
+
;
251
+
252
+
-- Create triggers for UPDATE operations
253
+
CREATE OR REPLACE TRIGGER notify_items_change_update
254
+
AFTER UPDATE ON pgstac.items
255
+
REFERENCING NEW TABLE AS data
256
+
FOR EACH STATEMENT EXECUTE FUNCTION notify_items_change_func()
257
+
;
258
+
259
+
-- Create triggers for DELETE operations
260
+
CREATE OR REPLACE TRIGGER notify_items_change_delete
261
+
AFTER DELETE ON pgstac.items
262
+
REFERENCING OLD TABLE AS data
263
+
FOR EACH STATEMENT EXECUTE FUNCTION notify_items_change_func()
264
+
;
265
+
```
266
+
267
+
#### Usage
268
+
269
+
Listen for notifications:
270
+
```sql
271
+
LISTEN pgstac_items_change;
272
+
```
273
+
274
+
Payload structure:
275
+
276
+
```json
277
+
{
278
+
"operation": "INSERT",
279
+
"items": [
280
+
{
281
+
"collection": "sentinel-2-l2a",
282
+
"id": "item-1"
283
+
},
284
+
{
285
+
"collection": "sentinel-2-l2a",
286
+
"id": "item-2"
287
+
}
288
+
]
289
+
}
290
+
```
291
+
292
+
#### Customization
293
+
294
+
You may modify the function to include additional metadata, filter by collection, or use different channels. Only trigger on the `items` table, not `items_staging`.
0 commit comments