*** a/doc/src/sgml/libpq.sgml --- b/doc/src/sgml/libpq.sgml *************** *** 2712,2720 **** char *PQresultErrorField(const PGresult *res, int fieldcode); PG_DIAG_TABLE_NAME ! If the error was associated with a specific table, the name of ! the table. (When this field is present, the schema name field ! provides the name of the table's schema.) --- 2712,2720 ---- PG_DIAG_TABLE_NAME ! If the error was associated with a specific table, the name of the ! table. (Refer to the schema name field for the name of the ! table's schema.) *************** *** 2723,2731 **** char *PQresultErrorField(const PGresult *res, int fieldcode); PG_DIAG_COLUMN_NAME ! If the error was associated with a specific table column, the ! name of the column. (When this field is present, the schema ! and table name fields identify the table.) --- 2723,2731 ---- PG_DIAG_COLUMN_NAME ! If the error was associated with a specific table column, the name ! of the column. (Refer to the schema and table name fields to ! identify the table.) *************** *** 2734,2742 **** char *PQresultErrorField(const PGresult *res, int fieldcode); PG_DIAG_DATATYPE_NAME ! If the error was associated with a specific data type, the name ! of the data type. (When this field is present, the schema name ! field provides the name of the data type's schema.) --- 2734,2742 ---- PG_DIAG_DATATYPE_NAME ! If the error was associated with a specific data type, the name of ! the data type. (Refer to the schema name field for the name of ! the data type's schema.) *************** *** 2745,2755 **** char *PQresultErrorField(const PGresult *res, int fieldcode); PG_DIAG_CONSTRAINT_NAME ! If the error was associated with a specific constraint, ! the name of the constraint. The table or domain that the ! constraint belongs to is reported using the fields listed ! above. (For this purpose, indexes are treated as constraints, ! even if they weren't created with constraint syntax.) --- 2745,2755 ---- PG_DIAG_CONSTRAINT_NAME ! If the error was associated with a specific constraint, the name ! of the constraint. Refer to fields listed above for the ! associated table or domain. (For this purpose, indexes are ! treated as constraints, even if they weren't created with ! constraint syntax.) *************** *** 2787,2795 **** char *PQresultErrorField(const PGresult *res, int fieldcode); ! The fields for schema name, table name, column name, data type ! name, and constraint name are supplied only for a limited number ! of error types; see . --- 2787,2800 ---- ! The fields for schema name, table name, column name, data type name, ! and constraint name are supplied only for a limited number of error ! types; see . Do not assume that ! the presence of any of these fields guarantees the presence of ! another field. Core error sources observe the interrelationships ! noted above, but user-defined functions may use these fields in other ! ways. In the same vein, do not assume that these fields denote ! contemporary objects in the current database. *** a/doc/src/sgml/plpgsql.sgml --- b/doc/src/sgml/plpgsql.sgml *************** *** 2665,2675 **** GET STACKED DIAGNOSTICS variable = item< --- 2665,2700 ---- the SQLSTATE error code of the exception + COLUMN_NAME + text + the name of column related to exception + + + CONSTRAINT_NAME + text + the name of constraint related to exception + + + PG_DATATYPE_NAME + text + the name of datatype related to exception + + MESSAGE_TEXT text the text of the exception's primary message + TABLE_NAME + text + the name of table related to exception + + + SCHEMA_NAME + text + the name of schema related to exception + + PG_EXCEPTION_DETAIL text the text of the exception's detail message, if any *************** *** 3355,3360 **** RAISE NOTICE 'Calling cs_create_job(%)', v_job_id; --- 3380,3396 ---- five-character SQLSTATE code. + + + COLUMN + CONSTRAINT + DATATYPE + TABLE + SCHEMA + + Supplies the name of a related object. + + *** a/doc/src/sgml/protocol.sgml --- b/doc/src/sgml/protocol.sgml *************** *** 4788,4795 **** message. Table name: if the error was associated with a specific table, the ! name of the table. (When this field is present, the schema name field ! provides the name of the table's schema.) --- 4788,4795 ---- Table name: if the error was associated with a specific table, the ! name of the table. (Refer to the schema name field for the name of ! the table's schema.) *************** *** 4801,4808 **** message. Column name: if the error was associated with a specific table column, ! the name of the column. (When this field is present, the schema and ! table name fields identify the table.) --- 4801,4808 ---- Column name: if the error was associated with a specific table column, ! the name of the column. (Refer to the schema and table name fields to ! identify the table.) *************** *** 4814,4821 **** message. Data type name: if the error was associated with a specific data type, ! the name of the data type. (When this field is present, the schema ! name field provides the name of the data type's schema.) --- 4814,4821 ---- Data type name: if the error was associated with a specific data type, ! the name of the data type. (Refer to the schema name field for the ! name of the data type's schema.) *************** *** 4827,4836 **** message. Constraint name: if the error was associated with a specific ! constraint, the name of the constraint. The table or domain that the ! constraint belongs to is reported using the fields listed above. (For ! this purpose, indexes are treated as constraints, even if they weren't ! created with constraint syntax.) --- 4827,4836 ---- Constraint name: if the error was associated with a specific ! constraint, the name of the constraint. Refer to fields listed above ! for the associated table or domain. (For this purpose, indexes are ! treated as constraints, even if they weren't created with constraint ! syntax.) *************** *** 4876,4882 **** message. The fields for schema name, table name, column name, data type name, and constraint name are supplied only for a limited number of error types; ! see . --- 4876,4887 ---- The fields for schema name, table name, column name, data type name, and constraint name are supplied only for a limited number of error types; ! see . Frontends should not assume that ! the presence of any of these fields guarantees the presence of another ! field. Core error sources observe the interrelationships noted above, but ! user-defined functions may use these fields in other ways. In the same ! vein, clients should not assume that these fields denote contemporary ! objects in the current database. *** a/src/pl/plpgsql/src/pl_exec.c --- b/src/pl/plpgsql/src/pl_exec.c *************** *** 1569,1579 **** exec_stmt_getdiag(PLpgSQL_execstate *estate, PLpgSQL_stmt_getdiag *stmt) --- 1569,1604 ---- unpack_sql_state(estate->cur_error->sqlerrcode)); break; + case PLPGSQL_GETDIAG_COLUMN_NAME: + exec_assign_c_string(estate, var, + estate->cur_error->column_name); + break; + + case PLPGSQL_GETDIAG_CONSTRAINT_NAME: + exec_assign_c_string(estate, var, + estate->cur_error->constraint_name); + break; + + case PLPGSQL_GETDIAG_DATATYPE_NAME: + exec_assign_c_string(estate, var, + estate->cur_error->datatype_name); + break; + case PLPGSQL_GETDIAG_MESSAGE_TEXT: exec_assign_c_string(estate, var, estate->cur_error->message); break; + case PLPGSQL_GETDIAG_TABLE_NAME: + exec_assign_c_string(estate, var, + estate->cur_error->table_name); + break; + + case PLPGSQL_GETDIAG_SCHEMA_NAME: + exec_assign_c_string(estate, var, + estate->cur_error->schema_name); + break; + default: elog(ERROR, "unrecognized diagnostic item kind: %d", diag_item->kind); *************** *** 2799,2804 **** exec_init_tuple_store(PLpgSQL_execstate *estate) --- 2824,2839 ---- estate->rettupdesc = rsi->expectedDesc; } + #define SET_RAISE_OPTION_TEXT(opt, name) \ + do { \ + if (opt) \ + ereport(ERROR, \ + (errcode(ERRCODE_SYNTAX_ERROR), \ + errmsg("RAISE option already specified: %s", \ + name))); \ + opt = pstrdup(extval); \ + } while (0) + /* ---------- * exec_stmt_raise Build a message and throw it with elog() * ---------- *************** *** 2811,2816 **** exec_stmt_raise(PLpgSQL_execstate *estate, PLpgSQL_stmt_raise *stmt) --- 2846,2856 ---- char *err_message = NULL; char *err_detail = NULL; char *err_hint = NULL; + char *err_column = NULL; + char *err_constraint = NULL; + char *err_datatype = NULL; + char *err_table = NULL; + char *err_schema = NULL; ListCell *lc; /* RAISE with no parameters: re-throw current exception */ *************** *** 2927,2954 **** exec_stmt_raise(PLpgSQL_execstate *estate, PLpgSQL_stmt_raise *stmt) condname = pstrdup(extval); break; case PLPGSQL_RAISEOPTION_MESSAGE: ! if (err_message) ! ereport(ERROR, ! (errcode(ERRCODE_SYNTAX_ERROR), ! errmsg("RAISE option already specified: %s", ! "MESSAGE"))); ! err_message = pstrdup(extval); break; case PLPGSQL_RAISEOPTION_DETAIL: ! if (err_detail) ! ereport(ERROR, ! (errcode(ERRCODE_SYNTAX_ERROR), ! errmsg("RAISE option already specified: %s", ! "DETAIL"))); ! err_detail = pstrdup(extval); break; case PLPGSQL_RAISEOPTION_HINT: ! if (err_hint) ! ereport(ERROR, ! (errcode(ERRCODE_SYNTAX_ERROR), ! errmsg("RAISE option already specified: %s", ! "HINT"))); ! err_hint = pstrdup(extval); break; default: elog(ERROR, "unrecognized raise option: %d", opt->opt_type); --- 2967,2994 ---- condname = pstrdup(extval); break; case PLPGSQL_RAISEOPTION_MESSAGE: ! SET_RAISE_OPTION_TEXT(err_message, "MESSAGE"); break; case PLPGSQL_RAISEOPTION_DETAIL: ! SET_RAISE_OPTION_TEXT(err_detail, "DETAIL"); break; case PLPGSQL_RAISEOPTION_HINT: ! SET_RAISE_OPTION_TEXT(err_hint, "HINT"); ! break; ! case PLPGSQL_RAISEOPTION_COLUMN: ! SET_RAISE_OPTION_TEXT(err_column, "COLUMN"); ! break; ! case PLPGSQL_RAISEOPTION_CONSTRAINT: ! SET_RAISE_OPTION_TEXT(err_constraint, "CONSTRAINT"); ! break; ! case PLPGSQL_RAISEOPTION_DATATYPE: ! SET_RAISE_OPTION_TEXT(err_datatype, "DATATYPE"); ! break; ! case PLPGSQL_RAISEOPTION_TABLE: ! SET_RAISE_OPTION_TEXT(err_table, "TABLE"); ! break; ! case PLPGSQL_RAISEOPTION_SCHEMA: ! SET_RAISE_OPTION_TEXT(err_schema, "SCHEMA"); break; default: elog(ERROR, "unrecognized raise option: %d", opt->opt_type); *************** *** 2982,2988 **** exec_stmt_raise(PLpgSQL_execstate *estate, PLpgSQL_stmt_raise *stmt) (err_code ? errcode(err_code) : 0, errmsg_internal("%s", err_message), (err_detail != NULL) ? errdetail_internal("%s", err_detail) : 0, ! (err_hint != NULL) ? errhint("%s", err_hint) : 0)); estate->err_text = NULL; /* un-suppress... */ --- 3022,3038 ---- (err_code ? errcode(err_code) : 0, errmsg_internal("%s", err_message), (err_detail != NULL) ? errdetail_internal("%s", err_detail) : 0, ! (err_hint != NULL) ? errhint("%s", err_hint) : 0, ! (err_column != NULL) ? ! err_generic_string(PG_DIAG_COLUMN_NAME, err_column) : 0, ! (err_constraint != NULL) ? ! err_generic_string(PG_DIAG_CONSTRAINT_NAME, err_constraint) : 0, ! (err_datatype != NULL) ? ! err_generic_string(PG_DIAG_DATATYPE_NAME, err_datatype) : 0, ! (err_table != NULL) ? ! err_generic_string(PG_DIAG_TABLE_NAME, err_table) : 0, ! (err_schema != NULL) ? ! err_generic_string(PG_DIAG_SCHEMA_NAME, err_schema) : 0)); estate->err_text = NULL; /* un-suppress... */ *************** *** 2994,2999 **** exec_stmt_raise(PLpgSQL_execstate *estate, PLpgSQL_stmt_raise *stmt) --- 3044,3059 ---- pfree(err_detail); if (err_hint != NULL) pfree(err_hint); + if (err_column != NULL) + pfree(err_column); + if (err_constraint != NULL) + pfree(err_constraint); + if (err_datatype != NULL) + pfree(err_datatype); + if (err_table != NULL) + pfree(err_table); + if (err_schema != NULL) + pfree(err_schema); return PLPGSQL_RC_OK; } *** a/src/pl/plpgsql/src/pl_funcs.c --- b/src/pl/plpgsql/src/pl_funcs.c *************** *** 285,292 **** plpgsql_getdiag_kindname(int kind) --- 285,302 ---- return "PG_EXCEPTION_HINT"; case PLPGSQL_GETDIAG_RETURNED_SQLSTATE: return "RETURNED_SQLSTATE"; + case PLPGSQL_GETDIAG_COLUMN_NAME: + return "COLUMN_NAME"; + case PLPGSQL_GETDIAG_CONSTRAINT_NAME: + return "CONSTRAINT_NAME"; + case PLPGSQL_GETDIAG_DATATYPE_NAME: + return "PG_DATATYPE_NAME"; case PLPGSQL_GETDIAG_MESSAGE_TEXT: return "MESSAGE_TEXT"; + case PLPGSQL_GETDIAG_TABLE_NAME: + return "TABLE_NAME"; + case PLPGSQL_GETDIAG_SCHEMA_NAME: + return "SCHEMA_NAME"; } return "unknown"; *************** *** 1317,1322 **** dump_raise(PLpgSQL_stmt_raise *stmt) --- 1327,1347 ---- case PLPGSQL_RAISEOPTION_HINT: printf(" HINT = "); break; + case PLPGSQL_RAISEOPTION_COLUMN: + printf(" COLUMN = "); + break; + case PLPGSQL_RAISEOPTION_CONSTRAINT: + printf(" CONSTRAINT = "); + break; + case PLPGSQL_RAISEOPTION_DATATYPE: + printf(" DATATYPE = "); + break; + case PLPGSQL_RAISEOPTION_TABLE: + printf(" TABLE = "); + break; + case PLPGSQL_RAISEOPTION_SCHEMA: + printf(" SCHEMA = "); + break; } dump_expr(opt->expr); printf("\n"); *** a/src/pl/plpgsql/src/pl_gram.y --- b/src/pl/plpgsql/src/pl_gram.y *************** *** 251,260 **** static List *read_raise_options(void); --- 251,265 ---- %token K_CASE %token K_CLOSE %token K_COLLATE + %token K_COLUMN + %token K_COLUMN_NAME %token K_CONSTANT + %token K_CONSTRAINT + %token K_CONSTRAINT_NAME %token K_CONTINUE %token K_CURRENT %token K_CURSOR + %token K_DATATYPE %token K_DEBUG %token K_DECLARE %token K_DEFAULT *************** *** 298,303 **** static List *read_raise_options(void); --- 303,309 ---- %token K_OPTION %token K_OR %token K_PERFORM + %token K_PG_DATATYPE_NAME %token K_PG_EXCEPTION_CONTEXT %token K_PG_EXCEPTION_DETAIL %token K_PG_EXCEPTION_HINT *************** *** 311,321 **** static List *read_raise_options(void); --- 317,331 ---- %token K_REVERSE %token K_ROWTYPE %token K_ROW_COUNT + %token K_SCHEMA + %token K_SCHEMA_NAME %token K_SCROLL %token K_SLICE %token K_SQLSTATE %token K_STACKED %token K_STRICT + %token K_TABLE + %token K_TABLE_NAME %token K_THEN %token K_TO %token K_TYPE *************** *** 896,902 **** stmt_getdiag : K_GET getdiag_area_opt K_DIAGNOSTICS getdiag_list ';' --- 906,917 ---- case PLPGSQL_GETDIAG_ERROR_DETAIL: case PLPGSQL_GETDIAG_ERROR_HINT: case PLPGSQL_GETDIAG_RETURNED_SQLSTATE: + case PLPGSQL_GETDIAG_COLUMN_NAME: + case PLPGSQL_GETDIAG_CONSTRAINT_NAME: + case PLPGSQL_GETDIAG_DATATYPE_NAME: case PLPGSQL_GETDIAG_MESSAGE_TEXT: + case PLPGSQL_GETDIAG_TABLE_NAME: + case PLPGSQL_GETDIAG_SCHEMA_NAME: if (!new->is_stacked) ereport(ERROR, (errcode(ERRCODE_SYNTAX_ERROR), *************** *** 971,979 **** getdiag_item : --- 986,1009 ---- K_PG_EXCEPTION_CONTEXT, "pg_exception_context")) $$ = PLPGSQL_GETDIAG_ERROR_CONTEXT; else if (tok_is_keyword(tok, &yylval, + K_COLUMN_NAME, "column_name")) + $$ = PLPGSQL_GETDIAG_COLUMN_NAME; + else if (tok_is_keyword(tok, &yylval, + K_CONSTRAINT_NAME, "constraint_name")) + $$ = PLPGSQL_GETDIAG_CONSTRAINT_NAME; + else if (tok_is_keyword(tok, &yylval, + K_PG_DATATYPE_NAME, "pg_datatype_name")) + $$ = PLPGSQL_GETDIAG_DATATYPE_NAME; + else if (tok_is_keyword(tok, &yylval, K_MESSAGE_TEXT, "message_text")) $$ = PLPGSQL_GETDIAG_MESSAGE_TEXT; else if (tok_is_keyword(tok, &yylval, + K_TABLE_NAME, "table_name")) + $$ = PLPGSQL_GETDIAG_TABLE_NAME; + else if (tok_is_keyword(tok, &yylval, + K_SCHEMA_NAME, "schema_name")) + $$ = PLPGSQL_GETDIAG_SCHEMA_NAME; + else if (tok_is_keyword(tok, &yylval, K_RETURNED_SQLSTATE, "returned_sqlstate")) $$ = PLPGSQL_GETDIAG_RETURNED_SQLSTATE; else *************** *** 2231,2239 **** unreserved_keyword : --- 2261,2274 ---- | K_ALIAS | K_ARRAY | K_BACKWARD + | K_COLUMN + | K_COLUMN_NAME | K_CONSTANT + | K_CONSTRAINT + | K_CONSTRAINT_NAME | K_CURRENT | K_CURSOR + | K_DATATYPE | K_DEBUG | K_DETAIL | K_DUMP *************** *** 2252,2257 **** unreserved_keyword : --- 2287,2293 ---- | K_NO | K_NOTICE | K_OPTION + | K_PG_DATATYPE_NAME | K_PG_EXCEPTION_CONTEXT | K_PG_EXCEPTION_DETAIL | K_PG_EXCEPTION_HINT *************** *** 2263,2272 **** unreserved_keyword : --- 2299,2312 ---- | K_REVERSE | K_ROW_COUNT | K_ROWTYPE + | K_SCHEMA + | K_SCHEMA_NAME | K_SCROLL | K_SLICE | K_SQLSTATE | K_STACKED + | K_TABLE + | K_TABLE_NAME | K_TYPE | K_USE_COLUMN | K_USE_VARIABLE *************** *** 3631,3636 **** read_raise_options(void) --- 3671,3691 ---- else if (tok_is_keyword(tok, &yylval, K_HINT, "hint")) opt->opt_type = PLPGSQL_RAISEOPTION_HINT; + else if (tok_is_keyword(tok, &yylval, + K_COLUMN, "column")) + opt->opt_type = PLPGSQL_RAISEOPTION_COLUMN; + else if (tok_is_keyword(tok, &yylval, + K_CONSTRAINT, "constraint")) + opt->opt_type = PLPGSQL_RAISEOPTION_CONSTRAINT; + else if (tok_is_keyword(tok, &yylval, + K_DATATYPE, "datatype")) + opt->opt_type = PLPGSQL_RAISEOPTION_DATATYPE; + else if (tok_is_keyword(tok, &yylval, + K_TABLE, "table")) + opt->opt_type = PLPGSQL_RAISEOPTION_TABLE; + else if (tok_is_keyword(tok, &yylval, + K_SCHEMA, "schema")) + opt->opt_type = PLPGSQL_RAISEOPTION_SCHEMA; else yyerror("unrecognized RAISE statement option"); *** a/src/pl/plpgsql/src/pl_scanner.c --- b/src/pl/plpgsql/src/pl_scanner.c *************** *** 109,117 **** static const ScanKeyword unreserved_keywords[] = { --- 109,122 ---- PG_KEYWORD("alias", K_ALIAS, UNRESERVED_KEYWORD) PG_KEYWORD("array", K_ARRAY, UNRESERVED_KEYWORD) PG_KEYWORD("backward", K_BACKWARD, UNRESERVED_KEYWORD) + PG_KEYWORD("column", K_COLUMN, UNRESERVED_KEYWORD) + PG_KEYWORD("column_name", K_COLUMN_NAME, UNRESERVED_KEYWORD) PG_KEYWORD("constant", K_CONSTANT, UNRESERVED_KEYWORD) + PG_KEYWORD("constraint", K_CONSTRAINT, UNRESERVED_KEYWORD) + PG_KEYWORD("constraint_name", K_CONSTRAINT_NAME, UNRESERVED_KEYWORD) PG_KEYWORD("current", K_CURRENT, UNRESERVED_KEYWORD) PG_KEYWORD("cursor", K_CURSOR, UNRESERVED_KEYWORD) + PG_KEYWORD("datatype", K_DATATYPE, UNRESERVED_KEYWORD) PG_KEYWORD("debug", K_DEBUG, UNRESERVED_KEYWORD) PG_KEYWORD("detail", K_DETAIL, UNRESERVED_KEYWORD) PG_KEYWORD("dump", K_DUMP, UNRESERVED_KEYWORD) *************** *** 130,135 **** static const ScanKeyword unreserved_keywords[] = { --- 135,141 ---- PG_KEYWORD("no", K_NO, UNRESERVED_KEYWORD) PG_KEYWORD("notice", K_NOTICE, UNRESERVED_KEYWORD) PG_KEYWORD("option", K_OPTION, UNRESERVED_KEYWORD) + PG_KEYWORD("pg_datatype_name", K_PG_DATATYPE_NAME, UNRESERVED_KEYWORD) PG_KEYWORD("pg_exception_context", K_PG_EXCEPTION_CONTEXT, UNRESERVED_KEYWORD) PG_KEYWORD("pg_exception_detail", K_PG_EXCEPTION_DETAIL, UNRESERVED_KEYWORD) PG_KEYWORD("pg_exception_hint", K_PG_EXCEPTION_HINT, UNRESERVED_KEYWORD) *************** *** 141,150 **** static const ScanKeyword unreserved_keywords[] = { --- 147,160 ---- PG_KEYWORD("reverse", K_REVERSE, UNRESERVED_KEYWORD) PG_KEYWORD("row_count", K_ROW_COUNT, UNRESERVED_KEYWORD) PG_KEYWORD("rowtype", K_ROWTYPE, UNRESERVED_KEYWORD) + PG_KEYWORD("schema", K_SCHEMA, UNRESERVED_KEYWORD) + PG_KEYWORD("schema_name", K_SCHEMA_NAME, UNRESERVED_KEYWORD) PG_KEYWORD("scroll", K_SCROLL, UNRESERVED_KEYWORD) PG_KEYWORD("slice", K_SLICE, UNRESERVED_KEYWORD) PG_KEYWORD("sqlstate", K_SQLSTATE, UNRESERVED_KEYWORD) PG_KEYWORD("stacked", K_STACKED, UNRESERVED_KEYWORD) + PG_KEYWORD("table", K_TABLE, UNRESERVED_KEYWORD) + PG_KEYWORD("table_name", K_TABLE_NAME, UNRESERVED_KEYWORD) PG_KEYWORD("type", K_TYPE, UNRESERVED_KEYWORD) PG_KEYWORD("use_column", K_USE_COLUMN, UNRESERVED_KEYWORD) PG_KEYWORD("use_variable", K_USE_VARIABLE, UNRESERVED_KEYWORD) *** a/src/pl/plpgsql/src/plpgsql.h --- b/src/pl/plpgsql/src/plpgsql.h *************** *** 128,134 **** enum PLPGSQL_GETDIAG_ERROR_DETAIL, PLPGSQL_GETDIAG_ERROR_HINT, PLPGSQL_GETDIAG_RETURNED_SQLSTATE, ! PLPGSQL_GETDIAG_MESSAGE_TEXT }; /* -------- --- 128,139 ---- PLPGSQL_GETDIAG_ERROR_DETAIL, PLPGSQL_GETDIAG_ERROR_HINT, PLPGSQL_GETDIAG_RETURNED_SQLSTATE, ! PLPGSQL_GETDIAG_COLUMN_NAME, ! PLPGSQL_GETDIAG_CONSTRAINT_NAME, ! PLPGSQL_GETDIAG_DATATYPE_NAME, ! PLPGSQL_GETDIAG_MESSAGE_TEXT, ! PLPGSQL_GETDIAG_TABLE_NAME, ! PLPGSQL_GETDIAG_SCHEMA_NAME }; /* -------- *************** *** 140,146 **** enum PLPGSQL_RAISEOPTION_ERRCODE, PLPGSQL_RAISEOPTION_MESSAGE, PLPGSQL_RAISEOPTION_DETAIL, ! PLPGSQL_RAISEOPTION_HINT }; /* -------- --- 145,156 ---- PLPGSQL_RAISEOPTION_ERRCODE, PLPGSQL_RAISEOPTION_MESSAGE, PLPGSQL_RAISEOPTION_DETAIL, ! PLPGSQL_RAISEOPTION_HINT, ! PLPGSQL_RAISEOPTION_COLUMN, ! PLPGSQL_RAISEOPTION_CONSTRAINT, ! PLPGSQL_RAISEOPTION_DATATYPE, ! PLPGSQL_RAISEOPTION_TABLE, ! PLPGSQL_RAISEOPTION_SCHEMA }; /* -------- *** a/src/test/regress/expected/plpgsql.out --- b/src/test/regress/expected/plpgsql.out *************** *** 3974,3979 **** select raise_test(); --- 3974,4013 ---- NOTICE: 22012 ERROR: substitute message 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(); + NOTICE: column >>some column name<<, constraint >>some constraint name<<, type >>some datatype name<<, table >>some table name<<, schema >>some schema name<< + stacked_diagnostics_test + -------------------------- + + (1 row) + + drop function stacked_diagnostics_test(); -- test CASE statement create or replace function case_test(bigint) returns text as $$ declare a int = 10; *** a/src/test/regress/sql/plpgsql.sql --- b/src/test/regress/sql/plpgsql.sql *************** *** 3262,3267 **** select raise_test(); --- 3262,3299 ---- 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 $$