2014-04-08 16:27:56 +02:00
|
|
|
--
|
|
|
|
-- regproc
|
|
|
|
--
|
|
|
|
|
|
|
|
/* If objects exist, return oids */
|
|
|
|
|
2016-07-18 00:42:31 +02:00
|
|
|
CREATE ROLE regress_regrole_test;
|
2016-01-04 07:03:53 +01:00
|
|
|
|
2014-04-08 16:27:56 +02:00
|
|
|
-- without schemaname
|
|
|
|
|
|
|
|
SELECT regoper('||/');
|
2014-04-16 18:21:43 +02:00
|
|
|
SELECT regoperator('+(int4,int4)');
|
2014-04-08 16:27:56 +02:00
|
|
|
SELECT regproc('now');
|
2014-04-16 18:21:43 +02:00
|
|
|
SELECT regprocedure('abs(numeric)');
|
2014-04-08 16:27:56 +02:00
|
|
|
SELECT regclass('pg_class');
|
|
|
|
SELECT regtype('int4');
|
2020-03-18 21:20:01 +01:00
|
|
|
SELECT regcollation('"POSIX"');
|
2014-04-08 16:27:56 +02:00
|
|
|
|
|
|
|
SELECT to_regoper('||/');
|
2014-04-16 18:21:43 +02:00
|
|
|
SELECT to_regoperator('+(int4,int4)');
|
2014-04-08 16:27:56 +02:00
|
|
|
SELECT to_regproc('now');
|
2014-04-16 18:21:43 +02:00
|
|
|
SELECT to_regprocedure('abs(numeric)');
|
2014-04-08 16:27:56 +02:00
|
|
|
SELECT to_regclass('pg_class');
|
|
|
|
SELECT to_regtype('int4');
|
2020-03-18 21:20:01 +01:00
|
|
|
SELECT to_regcollation('"POSIX"');
|
2014-04-08 16:27:56 +02:00
|
|
|
|
|
|
|
-- with schemaname
|
|
|
|
|
|
|
|
SELECT regoper('pg_catalog.||/');
|
2014-04-16 18:21:43 +02:00
|
|
|
SELECT regoperator('pg_catalog.+(int4,int4)');
|
2014-04-08 16:27:56 +02:00
|
|
|
SELECT regproc('pg_catalog.now');
|
2014-04-16 18:21:43 +02:00
|
|
|
SELECT regprocedure('pg_catalog.abs(numeric)');
|
2014-04-08 16:27:56 +02:00
|
|
|
SELECT regclass('pg_catalog.pg_class');
|
|
|
|
SELECT regtype('pg_catalog.int4');
|
2020-03-18 21:20:01 +01:00
|
|
|
SELECT regcollation('pg_catalog."POSIX"');
|
2014-04-08 16:27:56 +02:00
|
|
|
|
|
|
|
SELECT to_regoper('pg_catalog.||/');
|
|
|
|
SELECT to_regproc('pg_catalog.now');
|
2014-04-16 18:21:43 +02:00
|
|
|
SELECT to_regprocedure('pg_catalog.abs(numeric)');
|
2014-04-08 16:27:56 +02:00
|
|
|
SELECT to_regclass('pg_catalog.pg_class');
|
|
|
|
SELECT to_regtype('pg_catalog.int4');
|
2020-03-18 21:20:01 +01:00
|
|
|
SELECT to_regcollation('pg_catalog."POSIX"');
|
2014-04-08 16:27:56 +02:00
|
|
|
|
2016-01-04 07:03:53 +01:00
|
|
|
-- schemaname not applicable
|
|
|
|
|
2016-07-18 00:42:31 +02:00
|
|
|
SELECT regrole('regress_regrole_test');
|
|
|
|
SELECT regrole('"regress_regrole_test"');
|
2016-01-04 07:03:53 +01:00
|
|
|
SELECT regnamespace('pg_catalog');
|
|
|
|
SELECT regnamespace('"pg_catalog"');
|
|
|
|
|
2016-07-18 00:42:31 +02:00
|
|
|
SELECT to_regrole('regress_regrole_test');
|
|
|
|
SELECT to_regrole('"regress_regrole_test"');
|
2016-01-04 07:03:53 +01:00
|
|
|
SELECT to_regnamespace('pg_catalog');
|
|
|
|
SELECT to_regnamespace('"pg_catalog"');
|
|
|
|
|
2014-04-08 16:27:56 +02:00
|
|
|
/* If objects don't exist, raise errors. */
|
|
|
|
|
2016-07-18 00:42:31 +02:00
|
|
|
DROP ROLE regress_regrole_test;
|
2015-05-09 19:06:49 +02:00
|
|
|
|
2014-04-08 16:27:56 +02:00
|
|
|
-- without schemaname
|
|
|
|
|
|
|
|
SELECT regoper('||//');
|
2014-04-16 18:21:43 +02:00
|
|
|
SELECT regoperator('++(int4,int4)');
|
2014-04-08 16:27:56 +02:00
|
|
|
SELECT regproc('know');
|
2014-04-16 18:21:43 +02:00
|
|
|
SELECT regprocedure('absinthe(numeric)');
|
2014-04-08 16:27:56 +02:00
|
|
|
SELECT regclass('pg_classes');
|
|
|
|
SELECT regtype('int3');
|
|
|
|
|
|
|
|
-- with schemaname
|
|
|
|
|
|
|
|
SELECT regoper('ng_catalog.||/');
|
2014-04-16 18:21:43 +02:00
|
|
|
SELECT regoperator('ng_catalog.+(int4,int4)');
|
2014-04-08 16:27:56 +02:00
|
|
|
SELECT regproc('ng_catalog.now');
|
2014-04-16 18:21:43 +02:00
|
|
|
SELECT regprocedure('ng_catalog.abs(numeric)');
|
2014-04-08 16:27:56 +02:00
|
|
|
SELECT regclass('ng_catalog.pg_class');
|
|
|
|
SELECT regtype('ng_catalog.int4');
|
2022-12-27 19:06:42 +01:00
|
|
|
\set VERBOSITY sqlstate \\ -- error message is encoding-dependent
|
2020-03-18 21:20:01 +01:00
|
|
|
SELECT regcollation('ng_catalog."POSIX"');
|
2022-12-27 19:06:42 +01:00
|
|
|
\set VERBOSITY default
|
2014-04-08 16:27:56 +02:00
|
|
|
|
2016-01-04 07:03:53 +01:00
|
|
|
-- schemaname not applicable
|
|
|
|
|
2016-07-18 00:42:31 +02:00
|
|
|
SELECT regrole('regress_regrole_test');
|
|
|
|
SELECT regrole('"regress_regrole_test"');
|
2016-01-04 07:03:53 +01:00
|
|
|
SELECT regrole('Nonexistent');
|
|
|
|
SELECT regrole('"Nonexistent"');
|
|
|
|
SELECT regrole('foo.bar');
|
|
|
|
SELECT regnamespace('Nonexistent');
|
|
|
|
SELECT regnamespace('"Nonexistent"');
|
|
|
|
SELECT regnamespace('foo.bar');
|
|
|
|
|
2014-04-08 16:27:56 +02:00
|
|
|
/* If objects don't exist, return NULL with no error. */
|
|
|
|
|
|
|
|
-- without schemaname
|
|
|
|
|
|
|
|
SELECT to_regoper('||//');
|
2014-04-16 18:21:43 +02:00
|
|
|
SELECT to_regoperator('++(int4,int4)');
|
2014-04-08 16:27:56 +02:00
|
|
|
SELECT to_regproc('know');
|
2014-04-16 18:21:43 +02:00
|
|
|
SELECT to_regprocedure('absinthe(numeric)');
|
2014-04-08 16:27:56 +02:00
|
|
|
SELECT to_regclass('pg_classes');
|
|
|
|
SELECT to_regtype('int3');
|
2020-03-18 21:20:01 +01:00
|
|
|
SELECT to_regcollation('notacollation');
|
2014-04-08 16:27:56 +02:00
|
|
|
|
|
|
|
-- with schemaname
|
|
|
|
|
|
|
|
SELECT to_regoper('ng_catalog.||/');
|
2014-04-16 18:21:43 +02:00
|
|
|
SELECT to_regoperator('ng_catalog.+(int4,int4)');
|
2014-04-08 16:27:56 +02:00
|
|
|
SELECT to_regproc('ng_catalog.now');
|
2014-04-16 18:21:43 +02:00
|
|
|
SELECT to_regprocedure('ng_catalog.abs(numeric)');
|
2014-04-08 16:27:56 +02:00
|
|
|
SELECT to_regclass('ng_catalog.pg_class');
|
|
|
|
SELECT to_regtype('ng_catalog.int4');
|
2020-03-18 21:20:01 +01:00
|
|
|
SELECT to_regcollation('ng_catalog."POSIX"');
|
2016-01-04 07:03:53 +01:00
|
|
|
|
|
|
|
-- schemaname not applicable
|
|
|
|
|
2016-07-18 00:42:31 +02:00
|
|
|
SELECT to_regrole('regress_regrole_test');
|
|
|
|
SELECT to_regrole('"regress_regrole_test"');
|
2016-01-04 07:03:53 +01:00
|
|
|
SELECT to_regrole('foo.bar');
|
|
|
|
SELECT to_regrole('Nonexistent');
|
|
|
|
SELECT to_regrole('"Nonexistent"');
|
|
|
|
SELECT to_regrole('foo.bar');
|
|
|
|
SELECT to_regnamespace('Nonexistent');
|
|
|
|
SELECT to_regnamespace('"Nonexistent"');
|
|
|
|
SELECT to_regnamespace('foo.bar');
|
2022-12-27 18:26:01 +01:00
|
|
|
|
Add to_regtypemod function to extract typemod from a string type name.
In combination with to_regtype, this allows converting a string to
the "canonicalized" form emitted by format_type. That usage requires
parsing the string twice, which is slightly annoying but not really
too expensive. We considered alternatives such as returning a record
type, but that way was notationally uglier than this, and possibly
less flexible.
Like to_regtype(), we'd rather that this return NULL for any bad
input, but the underlying type-parsing logic isn't yet capable of
not throwing syntax errors. Adjust the documentation for both
functions to point that out.
In passing, fix up a couple of nearby entries in the System Catalog
Information Functions table that had not gotten the word about our
since-v13 convention for displaying function usage examples.
David Wheeler and Erik Wienhold, reviewed by Pavel Stehule, Jim Jones,
and others.
Discussion: https://postgr.es/m/DF2324CA-2673-4ABE-B382-26B5770B6AA3@justatheory.com
2024-03-20 22:11:23 +01:00
|
|
|
-- Test to_regtypemod
|
|
|
|
SELECT to_regtypemod('text');
|
|
|
|
SELECT to_regtypemod('timestamp(4)');
|
|
|
|
SELECT to_regtypemod('no_such_type(4)');
|
|
|
|
SELECT format_type(to_regtype('varchar(32)'), to_regtypemod('varchar(32)'));
|
|
|
|
SELECT format_type(to_regtype('bit'), to_regtypemod('bit'));
|
|
|
|
SELECT format_type(to_regtype('"bit"'), to_regtypemod('"bit"'));
|
|
|
|
|
2022-12-27 18:26:01 +01:00
|
|
|
-- Test soft-error API
|
|
|
|
|
2023-02-28 00:04:13 +01:00
|
|
|
SELECT * FROM pg_input_error_info('ng_catalog.pg_class', 'regclass');
|
2022-12-27 19:06:42 +01:00
|
|
|
SELECT pg_input_is_valid('ng_catalog."POSIX"', 'regcollation');
|
2023-02-28 00:04:13 +01:00
|
|
|
SELECT * FROM pg_input_error_info('no_such_config', 'regconfig');
|
|
|
|
SELECT * FROM pg_input_error_info('no_such_dictionary', 'regdictionary');
|
|
|
|
SELECT * FROM pg_input_error_info('Nonexistent', 'regnamespace');
|
|
|
|
SELECT * FROM pg_input_error_info('ng_catalog.||/', 'regoper');
|
|
|
|
SELECT * FROM pg_input_error_info('-', 'regoper');
|
|
|
|
SELECT * FROM pg_input_error_info('ng_catalog.+(int4,int4)', 'regoperator');
|
|
|
|
SELECT * FROM pg_input_error_info('-', 'regoperator');
|
|
|
|
SELECT * FROM pg_input_error_info('ng_catalog.now', 'regproc');
|
|
|
|
SELECT * FROM pg_input_error_info('ng_catalog.abs(numeric)', 'regprocedure');
|
|
|
|
SELECT * FROM pg_input_error_info('ng_catalog.abs(numeric', 'regprocedure');
|
|
|
|
SELECT * FROM pg_input_error_info('regress_regrole_test', 'regrole');
|
|
|
|
SELECT * FROM pg_input_error_info('no_such_type', 'regtype');
|
2022-12-27 18:26:01 +01:00
|
|
|
|
|
|
|
-- Some cases that should be soft errors, but are not yet
|
2023-02-28 00:04:13 +01:00
|
|
|
SELECT * FROM pg_input_error_info('incorrect type name syntax', 'regtype');
|
|
|
|
SELECT * FROM pg_input_error_info('numeric(1,2,3)', 'regtype'); -- bogus typmod
|
|
|
|
SELECT * FROM pg_input_error_info('way.too.many.names', 'regtype');
|
|
|
|
SELECT * FROM pg_input_error_info('no_such_catalog.schema.name', 'regtype');
|