diff options
author | Tom Lane | 2024-03-20 21:11:23 +0000 |
---|---|---|
committer | Tom Lane | 2024-03-20 21:11:28 +0000 |
commit | 1218ca9956ee60afc6975f14c1a4c953bd6bbaa7 (patch) | |
tree | 193accadb5fecf5c0866e522e77cd3bd090d184c /src/test | |
parent | 80686761c49d5194d224b344e968c26981611726 (diff) |
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
Diffstat (limited to 'src/test')
-rw-r--r-- | src/test/regress/expected/regproc.out | 37 | ||||
-rw-r--r-- | src/test/regress/sql/regproc.sql | 8 |
2 files changed, 45 insertions, 0 deletions
diff --git a/src/test/regress/expected/regproc.out b/src/test/regress/expected/regproc.out index a9420850b87..97b917502ca 100644 --- a/src/test/regress/expected/regproc.out +++ b/src/test/regress/expected/regproc.out @@ -447,6 +447,43 @@ SELECT to_regnamespace('foo.bar'); (1 row) +-- Test to_regtypemod +SELECT to_regtypemod('text'); + to_regtypemod +--------------- + -1 +(1 row) + +SELECT to_regtypemod('timestamp(4)'); + to_regtypemod +--------------- + 4 +(1 row) + +SELECT to_regtypemod('no_such_type(4)'); + to_regtypemod +--------------- + +(1 row) + +SELECT format_type(to_regtype('varchar(32)'), to_regtypemod('varchar(32)')); + format_type +----------------------- + character varying(32) +(1 row) + +SELECT format_type(to_regtype('bit'), to_regtypemod('bit')); + format_type +------------- + bit(1) +(1 row) + +SELECT format_type(to_regtype('"bit"'), to_regtypemod('"bit"')); + format_type +------------- + "bit" +(1 row) + -- Test soft-error API SELECT * FROM pg_input_error_info('ng_catalog.pg_class', 'regclass'); message | detail | hint | sql_error_code diff --git a/src/test/regress/sql/regproc.sql b/src/test/regress/sql/regproc.sql index de2aa881a8d..232289ac398 100644 --- a/src/test/regress/sql/regproc.sql +++ b/src/test/regress/sql/regproc.sql @@ -123,6 +123,14 @@ SELECT to_regnamespace('Nonexistent'); SELECT to_regnamespace('"Nonexistent"'); SELECT to_regnamespace('foo.bar'); +-- 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"')); + -- Test soft-error API SELECT * FROM pg_input_error_info('ng_catalog.pg_class', 'regclass'); |