Postgres
async with postgres.transaction(): | Runs the queries inside it as one transaction. An exception rolls it back |
UPDATE t SET ... WHERE ... RETURNING col | Returns the rows it changed, or [] if WHERE matched none |
SELECT ... FOR UPDATE | Locks the rows it reads until the transaction ends. Other writers and FOR UPDATEs wait |
SELECT ... ORDER BY id FOR UPDATE | Locks the rows in id order |
col TEXT PRIMARY KEY | No two rows share a value |
col BIGINT REFERENCES t (id) | Must match a row of t |
Each run builds the database from schema.sql and fills seats: id, section, and price_cents.
Errors
from framework import PostgresError
try:
async with postgres.transaction():
...
except PostgresError as exc:
...PostgresError | Raised when a statement fails. The transaction has been rolled back |
"duplicate key" in str(exc) | Whether it broke a unique constraint or primary key |
Arrays
{"ids": ["a", "b"]} as params | A Python list becomes an array |
x = ANY(arr) | Whether x is in arr |
unnest(arr) | One row per element |
Python · 104 linesStarter code · Ctrl/⌘ + Enter to run
SystemBroke
No runs yet.
Run the simulation to send this kata's traffic to your code. Hidden checks grade what it does.