Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
tasks=# BEGIN;
BEGIN
tasks=# SELECT * FROM tasks WHERE status = 'pending' ORDER BY created_at ASC LIMIT 1 FOR UPDATE SKIP LOCKED;
id | status | payload | created_at
----+---------+-------------------------------------------------------------------+----------------------------
1 | pending | { "action": "feed", "animal": "panda", "food": "kaiserschmarrn" } | 2019-09-19 15:39:49.459537
(1 row)
tasks=# SAVEPOINT task_1;
SAVEPOINT
tasks=# INSERT INTO projects (name) VALUES ('foobar');
ERROR: null value in column "namespace_id" violates not-null constraint
DETAIL: Failing row contains (20, foobar, null).
tasks=# ROLLBACK TO SAVEPOINT task_1;
ROLLBACK
tasks=# UPDATE tasks SET status = 'failed' WHERE id='1';
UPDATE 1
tasks=# COMMIT;
COMMIT
tasks=# SELECT * FROM tasks;
id | status | payload | created_at
----+--------+-------------------------------------------------------------------+----------------------------
1 | failed | { "action": "feed", "animal": "panda", "food": "kaiserschmarrn" } | 2019-09-19 15:39:49.459537
(1 row)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.