INSERT defaults and generated identifiers
Overview
A column default is used when the column is omitted, not when you explicitly supply NULL. An automatically generated identifier lets the database allocate a key instead of having the application guess the next number. The fixture uses SQLite INTEGER PRIMARY KEY (an alias for rowid in this ordinary table); PostgreSQL identity syntax is different. Load the V51 fixture and run each transaction independently.
First example
BEGIN;INSERT INTO ins_item(sku, price_cents) VALUES ('C3',200);SELECT id, quantity, note FROM ins_item WHERE sku='C3';ROLLBACK;Observed SQLite result (rows in JSON):
[ [ 3, 0, "pending" ]]How it works
quantity has default 0 and is NOT NULL; note has default pending but permits NULL. The first query omits both columns. The second explicitly supplies NULL for note, so the default is bypassed. DEFAULT VALUES creates one row using defaults, provided all required attributes can be satisfied. The fixture contains a separate ins_job table for that syntax. PostgreSQL supports the DEFAULT keyword within VALUES; SQLite 3.46.1 does not. Do not generate IDs with MAX(id)+1 in concurrent code, or assume IDs are gapless or never reused.
Practical example
BEGIN;INSERT INTO ins_item(sku,price_cents,note) VALUES ('C3',200,NULL);SELECT quantity,note FROM ins_item WHERE sku='C3';ROLLBACK;Observed SQLite result (rows in JSON):
[ [ 0, null ]]Practice and mistakes
Practice: in a fresh transaction, insert C3 with price 200, quantity 4 and no note. Query its ID, quantity and note; expect 3, 4 and pending for this fixture only. Try explicit NULL for quantity separately and explain the rejection. Run ROLLBACK after each attempt; the observed next ID is fixture-specific, not a general guarantee.
PostgreSQL 17 example — NOT RUN
CREATE TEMP TABLE pg_insert_demo (id integer GENERATED ALWAYS AS IDENTITY PRIMARY KEY, note text DEFAULT 'pending');INSERT INTO pg_insert_demo(note) VALUES (DEFAULT) RETURNING id,note;Expected result, not executed: [[1, "pending"]]