diff options
| author | Tom Lane | 2022-12-27 17:26:01 +0000 |
|---|---|---|
| committer | Tom Lane | 2022-12-27 17:26:01 +0000 |
| commit | 858e776c84f48841e7e16fba7b690b76e54f3675 (patch) | |
| tree | d66a1512ca446af90173d5ff8fd57863f98be6f7 /src/test | |
| parent | 78212f21011449f0374831323655baa7c00f3680 (diff) | |
Convert the reg* input functions to report (most) errors softly.
This is not really complete, but it catches most cases of practical
interest. The main omissions are:
* regtype, regprocedure, and regoperator parse type names by
calling the main grammar, so any grammar-detected syntax error
will still be a hard error. Also, if one includes a type
modifier in such a type specification, errors detected by the
typmodin function will be hard errors.
* Lookup errors are handled just by passing missing_ok = true
to the relevant catalog lookup function. Because we've used
quite a restrictive definition of "missing_ok", this means that
edge cases such as "the named schema exists, but you lack
USAGE permission on it" are still hard errors.
It would make sense to me to replace most/all missing_ok
parameters with an escontext parameter and then allow these
additional lookup failure cases to be trapped too. But that's
a job for some other day.
Discussion: https://postgr.es/m/3342239.1671988406@sss.pgh.pa.us
Diffstat (limited to 'src/test')
| -rw-r--r-- | src/test/regress/expected/regproc.out | 125 | ||||
| -rw-r--r-- | src/test/regress/sql/regproc.sql | 23 |
2 files changed, 140 insertions, 8 deletions
diff --git a/src/test/regress/expected/regproc.out b/src/test/regress/expected/regproc.out index e45ff5483fb..0c5e1d4be63 100644 --- a/src/test/regress/expected/regproc.out +++ b/src/test/regress/expected/regproc.out @@ -245,7 +245,7 @@ LINE 1: SELECT regtype('int3'); ^ -- with schemaname SELECT regoper('ng_catalog.||/'); -ERROR: schema "ng_catalog" does not exist +ERROR: operator does not exist: ng_catalog.||/ LINE 1: SELECT regoper('ng_catalog.||/'); ^ SELECT regoperator('ng_catalog.+(int4,int4)'); @@ -253,15 +253,15 @@ ERROR: operator does not exist: ng_catalog.+(int4,int4) LINE 1: SELECT regoperator('ng_catalog.+(int4,int4)'); ^ SELECT regproc('ng_catalog.now'); -ERROR: schema "ng_catalog" does not exist +ERROR: function "ng_catalog.now" does not exist LINE 1: SELECT regproc('ng_catalog.now'); ^ SELECT regprocedure('ng_catalog.abs(numeric)'); -ERROR: schema "ng_catalog" does not exist +ERROR: function "ng_catalog.abs(numeric)" does not exist LINE 1: SELECT regprocedure('ng_catalog.abs(numeric)'); ^ SELECT regclass('ng_catalog.pg_class'); -ERROR: schema "ng_catalog" does not exist +ERROR: relation "ng_catalog.pg_class" does not exist LINE 1: SELECT regclass('ng_catalog.pg_class'); ^ SELECT regtype('ng_catalog.int4'); @@ -269,7 +269,7 @@ ERROR: schema "ng_catalog" does not exist LINE 1: SELECT regtype('ng_catalog.int4'); ^ SELECT regcollation('ng_catalog."POSIX"'); -ERROR: schema "ng_catalog" does not exist +ERROR: collation "ng_catalog.POSIX" for encoding "SQL_ASCII" does not exist LINE 1: SELECT regcollation('ng_catalog."POSIX"'); ^ -- schemaname not applicable @@ -406,7 +406,11 @@ SELECT to_regrole('"regress_regrole_test"'); (1 row) SELECT to_regrole('foo.bar'); -ERROR: invalid name syntax + to_regrole +------------ + +(1 row) + SELECT to_regrole('Nonexistent'); to_regrole ------------ @@ -420,7 +424,11 @@ SELECT to_regrole('"Nonexistent"'); (1 row) SELECT to_regrole('foo.bar'); -ERROR: invalid name syntax + to_regrole +------------ + +(1 row) + SELECT to_regnamespace('Nonexistent'); to_regnamespace ----------------- @@ -434,4 +442,105 @@ SELECT to_regnamespace('"Nonexistent"'); (1 row) SELECT to_regnamespace('foo.bar'); -ERROR: invalid name syntax + to_regnamespace +----------------- + +(1 row) + +-- Test soft-error API +SELECT pg_input_error_message('ng_catalog.pg_class', 'regclass'); + pg_input_error_message +----------------------------------------------- + relation "ng_catalog.pg_class" does not exist +(1 row) + +SELECT pg_input_error_message('ng_catalog."POSIX"', 'regcollation'); + pg_input_error_message +---------------------------------------------------------------------- + collation "ng_catalog.POSIX" for encoding "SQL_ASCII" does not exist +(1 row) + +SELECT pg_input_error_message('no_such_config', 'regconfig'); + pg_input_error_message +----------------------------------------------------------- + text search configuration "no_such_config" does not exist +(1 row) + +SELECT pg_input_error_message('no_such_dictionary', 'regdictionary'); + pg_input_error_message +------------------------------------------------------------ + text search dictionary "no_such_dictionary" does not exist +(1 row) + +SELECT pg_input_error_message('Nonexistent', 'regnamespace'); + pg_input_error_message +------------------------------------- + schema "nonexistent" does not exist +(1 row) + +SELECT pg_input_error_message('ng_catalog.||/', 'regoper'); + pg_input_error_message +----------------------------------------- + operator does not exist: ng_catalog.||/ +(1 row) + +SELECT pg_input_error_message('-', 'regoper'); + pg_input_error_message +-------------------------------- + more than one operator named - +(1 row) + +SELECT pg_input_error_message('ng_catalog.+(int4,int4)', 'regoperator'); + pg_input_error_message +-------------------------------------------------- + operator does not exist: ng_catalog.+(int4,int4) +(1 row) + +SELECT pg_input_error_message('-', 'regoperator'); + pg_input_error_message +----------------------------- + expected a left parenthesis +(1 row) + +SELECT pg_input_error_message('ng_catalog.now', 'regproc'); + pg_input_error_message +------------------------------------------ + function "ng_catalog.now" does not exist +(1 row) + +SELECT pg_input_error_message('ng_catalog.abs(numeric)', 'regprocedure'); + pg_input_error_message +--------------------------------------------------- + function "ng_catalog.abs(numeric)" does not exist +(1 row) + +SELECT pg_input_error_message('ng_catalog.abs(numeric', 'regprocedure'); + pg_input_error_message +------------------------------ + expected a right parenthesis +(1 row) + +SELECT pg_input_error_message('regress_regrole_test', 'regrole'); + pg_input_error_message +-------------------------------------------- + role "regress_regrole_test" does not exist +(1 row) + +SELECT pg_input_error_message('no_such_type', 'regtype'); + pg_input_error_message +------------------------------------ + type "no_such_type" does not exist +(1 row) + +-- Some cases that should be soft errors, but are not yet +SELECT pg_input_error_message('incorrect type name syntax', 'regtype'); +ERROR: syntax error at or near "type" +LINE 1: SELECT pg_input_error_message('incorrect type name syntax', ... + ^ +CONTEXT: invalid type name "incorrect type name syntax" +SELECT pg_input_error_message('numeric(1,2,3)', 'regtype'); -- bogus typmod +ERROR: invalid NUMERIC type modifier +SELECT pg_input_error_message('way.too.many.names', 'regtype'); +ERROR: improper qualified name (too many dotted names): way.too.many.names +SELECT pg_input_error_message('no_such_catalog.schema.name', 'regtype'); +ERROR: cross-database references are not implemented: no_such_catalog.schema.name diff --git a/src/test/regress/sql/regproc.sql b/src/test/regress/sql/regproc.sql index faab0c15ce8..aa1f1bb17a2 100644 --- a/src/test/regress/sql/regproc.sql +++ b/src/test/regress/sql/regproc.sql @@ -120,3 +120,26 @@ SELECT to_regrole('foo.bar'); SELECT to_regnamespace('Nonexistent'); SELECT to_regnamespace('"Nonexistent"'); SELECT to_regnamespace('foo.bar'); + +-- Test soft-error API + +SELECT pg_input_error_message('ng_catalog.pg_class', 'regclass'); +SELECT pg_input_error_message('ng_catalog."POSIX"', 'regcollation'); +SELECT pg_input_error_message('no_such_config', 'regconfig'); +SELECT pg_input_error_message('no_such_dictionary', 'regdictionary'); +SELECT pg_input_error_message('Nonexistent', 'regnamespace'); +SELECT pg_input_error_message('ng_catalog.||/', 'regoper'); +SELECT pg_input_error_message('-', 'regoper'); +SELECT pg_input_error_message('ng_catalog.+(int4,int4)', 'regoperator'); +SELECT pg_input_error_message('-', 'regoperator'); +SELECT pg_input_error_message('ng_catalog.now', 'regproc'); +SELECT pg_input_error_message('ng_catalog.abs(numeric)', 'regprocedure'); +SELECT pg_input_error_message('ng_catalog.abs(numeric', 'regprocedure'); +SELECT pg_input_error_message('regress_regrole_test', 'regrole'); +SELECT pg_input_error_message('no_such_type', 'regtype'); + +-- Some cases that should be soft errors, but are not yet +SELECT pg_input_error_message('incorrect type name syntax', 'regtype'); +SELECT pg_input_error_message('numeric(1,2,3)', 'regtype'); -- bogus typmod +SELECT pg_input_error_message('way.too.many.names', 'regtype'); +SELECT pg_input_error_message('no_such_catalog.schema.name', 'regtype'); |
