successful completion
SQLSTATE 00000 indicates that the last SQL statement completed without error or warning. It is the "all clear" code returned by the server when a command succeeds normally.
- 1Normal, expected completion of any SQL statement with no anomalies
Any successfully executed SQL statement.
SELECT 1; -- SQLSTATE 00000
expected output
SELECT 1
Fix
Use SQLSTATE 00000 as the baseline success check in PL/pgSQL
WHEN When writing stored procedures or DO blocks that need to confirm a statement succeeded before continuing.
DO $
DECLARE
v_sqlstate TEXT;
BEGIN
INSERT INTO orders (user_id, total) VALUES (42, 99.99);
GET DIAGNOSTICS v_sqlstate = RETURNED_SQLSTATE;
IF v_sqlstate = '00000' THEN
RAISE NOTICE 'Insert succeeded (SQLSTATE %)' , v_sqlstate;
END IF;
EXCEPTION WHEN OTHERS THEN
RAISE WARNING 'Statement failed: %', SQLERRM;
END;
$;Why this works
In PL/pgSQL, GET DIAGNOSTICS ... = RETURNED_SQLSTATE captures the SQLSTATE of the most recent SQL statement. A value of 00000 confirms clean completion with no warnings or errors. This is useful when a procedure must audit its own intermediate steps before committing.
Class 00 — Successful Completion
Content generated with AI assistance and reviewed for accuracy. Found an error? hello@errcodes.dev