uqa-sql 0.6.2

PostgreSQL-compatible SQL compiler built on libpg_query
Documentation
1
{"postgresql_version":"PostgreSQL 18.4 (Debian 18.4-1.pgdg13+1) on aarch64-unknown-linux-gnu, compiled by gcc (Debian 14.2.0-19) 14.2.0, 64-bit","cases":[{"sql":"SELECT version()","command_tags":["SELECT 1"],"error":null,"results":[{"columns":["version"],"type_oids":[25],"rows":[["PostgreSQL 18.4 (Debian 18.4-1.pgdg13+1) on aarch64-unknown-linux-gnu, compiled by gcc (Debian 14.2.0-19) 14.2.0, 64-bit"]]}],"notices":[]},{"sql":"CREATE SCHEMA uqa_procedural_78a4","command_tags":["CREATE SCHEMA"],"error":null,"results":[{"columns":[],"type_oids":[],"rows":[]}],"notices":[]},{"sql":"SET search_path = uqa_procedural_78a4, pg_catalog","command_tags":["SET"],"error":null,"results":[{"columns":[],"type_oids":[],"rows":[]}],"notices":[]},{"sql":"CREATE SEQUENCE defaults_seen","command_tags":["CREATE SEQUENCE"],"error":null,"results":[{"columns":[],"type_oids":[],"rows":[]}],"notices":[]},{"sql":"CREATE SEQUENCE domain_checks","command_tags":["CREATE SEQUENCE"],"error":null,"results":[{"columns":[],"type_oids":[],"rows":[]}],"notices":[]},{"sql":"CREATE TABLE permission(allowed boolean)","command_tags":["CREATE TABLE"],"error":null,"results":[{"columns":[],"type_oids":[],"rows":[]}],"notices":[]},{"sql":"INSERT INTO permission VALUES (true)","command_tags":["INSERT 0 1"],"error":null,"results":[{"columns":[],"type_oids":[],"rows":[]}],"notices":[]},{"sql":"CREATE FUNCTION accepts_value(x integer) RETURNS boolean LANGUAGE plpgsql VOLATILE AS $$ BEGIN PERFORM nextval('domain_checks'); RETURN (SELECT allowed FROM permission); END $$","command_tags":["CREATE FUNCTION"],"error":null,"results":[{"columns":[],"type_oids":[],"rows":[]}],"notices":[]},{"sql":"CREATE DOMAIN checked_integer AS integer CHECK (accepts_value(VALUE))","command_tags":["CREATE DOMAIN"],"error":null,"results":[{"columns":[],"type_oids":[],"rows":[]}],"notices":[]},{"sql":"CREATE FUNCTION assign_checked(x integer) RETURNS integer LANGUAGE plpgsql VOLATILE AS $$ DECLARE v checked_integer; BEGIN v := x; RETURN v::integer; END $$","command_tags":["CREATE FUNCTION"],"error":null,"results":[{"columns":[],"type_oids":[],"rows":[]}],"notices":[]},{"sql":"CREATE FUNCTION return_checked(x integer) RETURNS checked_integer LANGUAGE plpgsql VOLATILE AS $$ BEGIN RETURN x; END $$","command_tags":["CREATE FUNCTION"],"error":null,"results":[{"columns":[],"type_oids":[],"rows":[]}],"notices":[]},{"sql":"SELECT i, assign_checked(i) AS value FROM generate_series(1, 3) t(i) ORDER BY i","command_tags":["SELECT 3"],"error":null,"results":[{"columns":["i","value"],"type_oids":[23,23],"rows":[["1","1"],["2","2"],["3","3"]]}],"notices":[],"id":"changing assignment values"},{"sql":"SELECT last_value FROM domain_checks","command_tags":["SELECT 1"],"error":null,"results":[{"columns":["last_value"],"type_oids":[20],"rows":[["6"]]}],"notices":[],"id":"initialization and assignment checks"},{"sql":"SELECT i, return_checked(i) AS value FROM generate_series(1, 3) t(i) ORDER BY i","command_tags":["SELECT 3"],"error":null,"results":[{"columns":["i","value"],"type_oids":[23,23],"rows":[["1","1"],["2","2"],["3","3"]]}],"notices":[],"id":"changing return values"},{"sql":"SELECT last_value FROM domain_checks","command_tags":["SELECT 1"],"error":null,"results":[{"columns":["last_value"],"type_oids":[20],"rows":[["9"]]}],"notices":[],"id":"return checks stay live"},{"sql":"SELECT assign_checked(NULL) AS a, return_checked(NULL) AS b","command_tags":["SELECT 1"],"error":null,"results":[{"columns":["a","b"],"type_oids":[23,23],"rows":[[null,null]]}],"notices":[],"id":"typed null values"},{"sql":"SELECT last_value FROM domain_checks","command_tags":["SELECT 1"],"error":null,"results":[{"columns":["last_value"],"type_oids":[20],"rows":[["12"]]}],"notices":[],"id":"null checks stay live"},{"sql":"UPDATE permission SET allowed = false","command_tags":["UPDATE 1"],"error":null,"results":[{"columns":[],"type_oids":[],"rows":[]}],"notices":[]},{"sql":"SELECT assign_checked(8)","command_tags":[],"error":{"sqlstate":"23514","message":"value for domain checked_integer violates check constraint \"checked_integer_check\"","detail":null,"hint":null},"results":[],"notices":[],"id":"declaration domain error"},{"sql":"SELECT return_checked(9)","command_tags":[],"error":{"sqlstate":"23514","message":"value for domain checked_integer violates check constraint \"checked_integer_check\"","detail":null,"hint":null},"results":[],"notices":[],"id":"return domain error"},{"sql":"UPDATE permission SET allowed = true","command_tags":["UPDATE 1"],"error":null,"results":[{"columns":[],"type_oids":[],"rows":[]}],"notices":[]},{"sql":"SELECT assign_checked(10) AS value","command_tags":["SELECT 1"],"error":null,"results":[{"columns":["value"],"type_oids":[23],"rows":[["10"]]}],"notices":[],"id":"domain recovers"},{"sql":"CREATE FUNCTION local_defaults(x integer) RETURNS bigint LANGUAGE plpgsql VOLATILE AS $$ DECLARE total bigint := 0; BEGIN FOR i IN 1..x LOOP DECLARE v bigint DEFAULT nextval('defaults_seen'); BEGIN total := total + v; END; END LOOP; RETURN total; END $$","command_tags":["CREATE FUNCTION"],"error":null,"results":[{"columns":[],"type_oids":[],"rows":[]}],"notices":[]},{"sql":"SELECT i, local_defaults(2) AS value FROM generate_series(1, 3) t(i) ORDER BY i","command_tags":["SELECT 3"],"error":null,"results":[{"columns":["i","value"],"type_oids":[23,20],"rows":[["1","3"],["2","7"],["3","11"]]}],"notices":[],"id":"block defaults per entry"},{"sql":"CREATE FUNCTION local_types(x smallint) RETURNS text LANGUAGE plpgsql AS $$ DECLARE v smallint := x; BEGIN RETURN pg_typeof(v)::text || ':' || COALESCE(v::text, 'null'); END $$","command_tags":["CREATE FUNCTION"],"error":null,"results":[{"columns":[],"type_oids":[],"rows":[]}],"notices":[]},{"sql":"SELECT local_types(1::smallint) AS a, local_types(NULL::smallint) AS b","command_tags":["SELECT 1"],"error":null,"results":[{"columns":["a","b"],"type_oids":[25,25],"rows":[["smallint:1","smallint:null"]]}],"notices":[],"id":"smallint width and null"},{"sql":"CREATE FUNCTION shadowed(x integer) RETURNS text LANGUAGE plpgsql AS $$ DECLARE v smallint := x; result text := ''; BEGIN result := pg_typeof(v)::text; DECLARE v text := 'current'; BEGIN result := result || ':' || pg_typeof(v)::text || ':' || v; END; RETURN result || ':' || v::text; END $$","command_tags":["CREATE FUNCTION"],"error":null,"results":[{"columns":[],"type_oids":[],"rows":[]}],"notices":[]},{"sql":"SELECT i, shadowed(i) AS value FROM generate_series(1, 3) t(i) ORDER BY i","command_tags":["SELECT 3"],"error":null,"results":[{"columns":["i","value"],"type_oids":[23,25],"rows":[["1","smallint:text:current:1"],["2","smallint:text:current:2"],["3","smallint:text:current:3"]]}],"notices":[],"id":"lexical shadowing"},{"sql":"CREATE FUNCTION record_values(x smallint) RETURNS text LANGUAGE plpgsql AS $$ DECLARE r record; result text; BEGIN SELECT x AS value INTO r; result := pg_typeof(r.value)::text || ':' || COALESCE(r.value::text, 'null'); SELECT 'next'::text AS value INTO r; RETURN result || ':' || pg_typeof(r.value)::text || ':' || r.value; END $$","command_tags":["CREATE FUNCTION"],"error":null,"results":[{"columns":[],"type_oids":[],"rows":[]}],"notices":[]},{"sql":"SELECT record_values(7::smallint) AS a, record_values(NULL::smallint) AS b","command_tags":["SELECT 1"],"error":null,"results":[{"columns":["a","b"],"type_oids":[25,25],"rows":[["smallint:7:text:next","smallint:null:text:next"]]}],"notices":[],"id":"current record schemas"},{"sql":"CREATE FUNCTION record_loop() RETURNS text LANGUAGE plpgsql AS $$ DECLARE r record; answer text; BEGIN FOR i IN 1..2 LOOP IF i = 1 THEN SELECT 7::smallint AS value INTO r; ELSE SELECT 'changed'::text AS value INTO r; END IF; answer := r.value::text; END LOOP; RETURN answer; END $$","command_tags":["CREATE FUNCTION"],"error":null,"results":[{"columns":[],"type_oids":[],"rows":[]}],"notices":[]},{"sql":"SELECT record_loop()","command_tags":[],"error":{"sqlstate":"42804","message":"type of parameter 5 (text) does not match that when preparing the plan (smallint)","detail":null,"hint":null},"results":[],"notices":[],"id":"prepared record type mismatch"},{"sql":"CREATE FUNCTION unassigned_record() RETURNS text LANGUAGE plpgsql AS $$ DECLARE r record; BEGIN RETURN r.value::text; END $$","command_tags":["CREATE FUNCTION"],"error":null,"results":[{"columns":[],"type_oids":[],"rows":[]}],"notices":[]},{"sql":"SELECT unassigned_record()","command_tags":[],"error":{"sqlstate":"55000","message":"record \"r\" is not assigned yet","detail":"The tuple structure of a not-yet-assigned record is indeterminate.","hint":null},"results":[],"notices":[],"id":"unassigned record error"},{"sql":"CREATE FUNCTION unassigned_assignment() RETURNS integer LANGUAGE plpgsql AS $$ DECLARE r record; BEGIN r.value := 1; RETURN 1; END $$","command_tags":["CREATE FUNCTION"],"error":null,"results":[{"columns":[],"type_oids":[],"rows":[]}],"notices":[]},{"sql":"SELECT unassigned_assignment()","command_tags":[],"error":{"sqlstate":"55000","message":"record \"r\" is not assigned yet","detail":"The tuple structure of a not-yet-assigned record is indeterminate.","hint":null},"results":[],"notices":[],"id":"unassigned record assignment error"},{"sql":"CREATE FUNCTION conditional_record(initialized boolean) RETURNS text LANGUAGE plpgsql AS $$ DECLARE r record; BEGIN IF initialized THEN SELECT 7::smallint AS value INTO r; END IF; RETURN r.value::text; END $$","command_tags":["CREATE FUNCTION"],"error":null,"results":[{"columns":[],"type_oids":[],"rows":[]}],"notices":[]},{"sql":"SELECT conditional_record(true)","command_tags":["SELECT 1"],"error":null,"results":[{"columns":["conditional_record"],"type_oids":[25],"rows":[["7"]]}],"notices":[],"id":"prepared record first assignment"},{"sql":"SELECT conditional_record(false)","command_tags":[],"error":{"sqlstate":"55000","message":"record \"r\" is not assigned yet","detail":"The tuple structure of a not-yet-assigned record is indeterminate.","hint":null},"results":[],"notices":[],"id":"prepared unassigned record error"},{"sql":"SELECT conditional_record(true)","command_tags":["SELECT 1"],"error":null,"results":[{"columns":["conditional_record"],"type_oids":[25],"rows":[["7"]]}],"notices":[],"id":"prepared record assignment after error"},{"sql":"CREATE FUNCTION lazy_record(initialized boolean) RETURNS text LANGUAGE plpgsql AS $$ DECLARE r record; BEGIN IF initialized THEN SELECT 8::smallint AS value INTO r; END IF; RETURN CASE WHEN initialized THEN r.value::text ELSE 'not read' END; END $$","command_tags":["CREATE FUNCTION"],"error":null,"results":[{"columns":[],"type_oids":[],"rows":[]}],"notices":[]},{"sql":"SELECT lazy_record(true)","command_tags":["SELECT 1"],"error":null,"results":[{"columns":["lazy_record"],"type_oids":[25],"rows":[["8"]]}],"notices":[],"id":"lazy record first assignment"},{"sql":"SELECT lazy_record(false)","command_tags":["SELECT 1"],"error":null,"results":[{"columns":["lazy_record"],"type_oids":[25],"rows":[["not read"]]}],"notices":[],"id":"unread deferred record error"},{"sql":"SELECT lazy_record(true)","command_tags":["SELECT 1"],"error":null,"results":[{"columns":["lazy_record"],"type_oids":[25],"rows":[["8"]]}],"notices":[],"id":"lazy record assignment after unread error"},{"sql":"CREATE FUNCTION missing_field() RETURNS text LANGUAGE plpgsql AS $$ DECLARE r record; BEGIN SELECT 1 AS present INTO r; RETURN r.absent::text; END $$","command_tags":["CREATE FUNCTION"],"error":null,"results":[{"columns":[],"type_oids":[],"rows":[]}],"notices":[]},{"sql":"SELECT missing_field()","command_tags":[],"error":{"sqlstate":"42703","message":"record \"r\" has no field \"absent\"","detail":null,"hint":null},"results":[],"notices":[],"id":"missing record field error"},{"sql":"CREATE FUNCTION null_assignment() RETURNS integer LANGUAGE plpgsql AS $$ DECLARE v integer NOT NULL := 1; BEGIN v := NULL; RETURN v; END $$","command_tags":["CREATE FUNCTION"],"error":null,"results":[{"columns":[],"type_oids":[],"rows":[]}],"notices":[]},{"sql":"SELECT null_assignment()","command_tags":[],"error":{"sqlstate":"22004","message":"null value cannot be assigned to variable \"v\" declared NOT NULL","detail":null,"hint":null},"results":[],"notices":[],"id":"not null assignment error"},{"sql":"CREATE FUNCTION lazy_declaration(run boolean) RETURNS integer LANGUAGE plpgsql AS $$ BEGIN IF run THEN DECLARE v integer NOT NULL := NULL; BEGIN RETURN v; END; END IF; RETURN 7; END $$","command_tags":["CREATE FUNCTION"],"error":null,"results":[{"columns":[],"type_oids":[],"rows":[]}],"notices":[]},{"sql":"SELECT lazy_declaration(false) AS value","command_tags":["SELECT 1"],"error":null,"results":[{"columns":["value"],"type_oids":[23],"rows":[["7"]]}],"notices":[],"id":"unreached declaration stays lazy"},{"sql":"SELECT lazy_declaration(true)","command_tags":[],"error":{"sqlstate":"22004","message":"null value cannot be assigned to variable \"v\" declared NOT NULL","detail":null,"hint":null},"results":[],"notices":[],"id":"reached declaration error"},{"sql":"CREATE FUNCTION caught_error() RETURNS text LANGUAGE plpgsql AS $$ BEGIN BEGIN RAISE EXCEPTION 'observed'; EXCEPTION WHEN OTHERS THEN RETURN SQLSTATE || ':' || SQLERRM; END; END $$","command_tags":["CREATE FUNCTION"],"error":null,"results":[{"columns":[],"type_oids":[],"rows":[]}],"notices":[]},{"sql":"SELECT caught_error() AS value","command_tags":["SELECT 1"],"error":null,"results":[{"columns":["value"],"type_oids":[25],"rows":[["P0001:observed"]]}],"notices":[],"id":"exception diagnostic variables"},{"sql":"CREATE TYPE held_pair AS (a integer, b text)","command_tags":["CREATE TYPE"],"error":null,"results":[{"columns":[],"type_oids":[],"rows":[]}],"notices":[]},{"sql":"CREATE FUNCTION retained_field() RETURNS integer LANGUAGE plpgsql AS $$ DECLARE r held_pair; BEGIN r := ROW(7, 'old')::held_pair; EXECUTE 'ALTER TYPE uqa_procedural_78a4.held_pair ADD ATTRIBUTE c integer'; RETURN r.a; END $$","command_tags":["CREATE FUNCTION"],"error":null,"results":[{"columns":[],"type_oids":[],"rows":[]}],"notices":[]},{"sql":"BEGIN","command_tags":["BEGIN"],"error":null,"results":[{"columns":[],"type_oids":[],"rows":[]}],"notices":[]},{"sql":"SELECT retained_field() AS value","command_tags":["SELECT 1"],"error":null,"results":[{"columns":["value"],"type_oids":[23],"rows":[["7"]]}],"notices":[],"id":"defined retained field after type change"},{"sql":"ROLLBACK","command_tags":["ROLLBACK"],"error":null,"results":[{"columns":[],"type_oids":[],"rows":[]}],"notices":[]},{"sql":"CREATE FUNCTION replacement(x integer) RETURNS integer LANGUAGE plpgsql AS $$ DECLARE v integer := x; BEGIN RETURN v + 1; END $$","command_tags":["CREATE FUNCTION"],"error":null,"results":[{"columns":[],"type_oids":[],"rows":[]}],"notices":[]},{"sql":"PREPARE selected(integer) AS SELECT replacement($1) AS value","command_tags":["PREPARE"],"error":null,"results":[{"columns":[],"type_oids":[],"rows":[]}],"notices":[]},{"sql":"EXECUTE selected(2)","command_tags":["SELECT 1"],"error":null,"results":[{"columns":["value"],"type_oids":[23],"rows":[["3"]]}],"notices":[],"id":"prepared first body"},{"sql":"BEGIN","command_tags":["BEGIN"],"error":null,"results":[{"columns":[],"type_oids":[],"rows":[]}],"notices":[]},{"sql":"CREATE OR REPLACE FUNCTION replacement(x integer) RETURNS integer LANGUAGE plpgsql AS $$ DECLARE v integer := x; BEGIN RETURN v + 10; END $$","command_tags":["CREATE FUNCTION"],"error":null,"results":[{"columns":[],"type_oids":[],"rows":[]}],"notices":[]},{"sql":"EXECUTE selected(2)","command_tags":["SELECT 1"],"error":null,"results":[{"columns":["value"],"type_oids":[23],"rows":[["12"]]}],"notices":[],"id":"replacement body"},{"sql":"ROLLBACK","command_tags":["ROLLBACK"],"error":null,"results":[{"columns":[],"type_oids":[],"rows":[]}],"notices":[]},{"sql":"EXECUTE selected(2)","command_tags":["SELECT 1"],"error":null,"results":[{"columns":["value"],"type_oids":[23],"rows":[["3"]]}],"notices":[],"id":"rollback restores body"},{"sql":"DEALLOCATE selected","command_tags":["DEALLOCATE"],"error":null,"results":[{"columns":[],"type_oids":[],"rows":[]}],"notices":[]},{"sql":"SET search_path = uqa_procedural_78a4, pg_catalog","command_tags":["SET"],"error":null,"results":[{"columns":[],"type_oids":[],"rows":[]}],"notices":[],"reopen":true},{"sql":"SELECT local_types(NULL::smallint) AS a, record_values(8::smallint) AS b, shadowed(9) AS c, replacement(3) AS d","command_tags":["SELECT 1"],"error":null,"results":[{"columns":["a","b","c","d"],"type_oids":[25,25,25,23],"rows":[["smallint:null","smallint:8:text:next","smallint:text:current:9","4"]]}],"notices":[],"id":"persisted types and body","reopen":true},{"sql":"DROP SCHEMA uqa_procedural_78a4 CASCADE","command_tags":["DROP SCHEMA"],"error":null,"results":[{"columns":[],"type_oids":[],"rows":[]}],"notices":[{"severity":"NOTICE","sqlstate":"00000","message":"drop cascades to 23 other objects","detail":"drop cascades to sequence defaults_seen\ndrop cascades to sequence domain_checks\ndrop cascades to table permission\ndrop cascades to function accepts_value(integer)\ndrop cascades to type checked_integer\ndrop cascades to function assign_checked(integer)\ndrop cascades to function return_checked(integer)\ndrop cascades to function local_defaults(integer)\ndrop cascades to function local_types(smallint)\ndrop cascades to function shadowed(integer)\ndrop cascades to function record_values(smallint)\ndrop cascades to function record_loop()\ndrop cascades to function unassigned_record()\ndrop cascades to function unassigned_assignment()\ndrop cascades to function conditional_record(boolean)\ndrop cascades to function lazy_record(boolean)\ndrop cascades to function missing_field()\ndrop cascades to function null_assignment()\ndrop cascades to function lazy_declaration(boolean)\ndrop cascades to function caught_error()\ndrop cascades to type held_pair\ndrop cascades to function retained_field()\ndrop cascades to function replacement(integer)","hint":null}],"final_cleanup":true}],"provenance":{"reference":"PostgreSQL 18.4 in a disposable Docker database","tool":"tests/parity/pg18/capture_command_completion_oracle.py","tool_sha256":"03c5af634def87180984276a560f34f40c1a97be76af76547e00eb6f186d57e0","input_sha256":"305768c4a523e1cb61bdacbc14eb7db72594ce2b69ff3fca9c26c4cf98af8ab4","options":["--rows","--details","--notices"]}}