mirror of
https://git.postgresql.org/git/postgresql.git
synced 2026-02-08 20:47:38 +08:00
Expose object name error fields in PL/pgSQL.
Specifically, permit attaching them to the error in RAISE and retrieving them from a caught error in GET STACKED DIAGNOSTICS. RAISE enforces nothing about the content of the fields; for its purposes, they are just additional string fields. Consequently, clarify in the protocol and libpq documentation that the usual relationships between error fields, like a schema name appearing wherever a table name appears, are not universal. This freedom has other applications; consider a FDW propagating an error from an RDBMS having no schema support. Back-patch to 9.3, where core support for the error fields was introduced. This prevents the confusion of having a release where libpq exposes the fields and PL/pgSQL does not. Pavel Stehule, lexical revisions by Noah Misch.
This commit is contained in:
@ -3262,6 +3262,38 @@ select raise_test();
|
||||
|
||||
drop function raise_test();
|
||||
|
||||
-- test passing column_name, constraint_name, datatype_name, table_name
|
||||
-- and schema_name error fields
|
||||
|
||||
create or replace function stacked_diagnostics_test() returns void as $$
|
||||
declare _column_name text;
|
||||
_constraint_name text;
|
||||
_datatype_name text;
|
||||
_table_name text;
|
||||
_schema_name text;
|
||||
begin
|
||||
raise exception using
|
||||
column = '>>some column name<<',
|
||||
constraint = '>>some constraint name<<',
|
||||
datatype = '>>some datatype name<<',
|
||||
table = '>>some table name<<',
|
||||
schema = '>>some schema name<<';
|
||||
exception when others then
|
||||
get stacked diagnostics
|
||||
_column_name = column_name,
|
||||
_constraint_name = constraint_name,
|
||||
_datatype_name = pg_datatype_name,
|
||||
_table_name = table_name,
|
||||
_schema_name = schema_name;
|
||||
raise notice 'column %, constraint %, type %, table %, schema %',
|
||||
_column_name, _constraint_name, _datatype_name, _table_name, _schema_name;
|
||||
end;
|
||||
$$ language plpgsql;
|
||||
|
||||
select stacked_diagnostics_test();
|
||||
|
||||
drop function stacked_diagnostics_test();
|
||||
|
||||
-- test CASE statement
|
||||
|
||||
create or replace function case_test(bigint) returns text as $$
|
||||
|
||||
Reference in New Issue
Block a user