Skip to content

Commit ea0d494

Browse files
committed
Make the to_reg*() functions accept text not cstring.
Using cstring as the input type was a poor decision, because that's not really a full-fledged type. In particular, it lacks implicit coercions from text or varchar, meaning that usages like to_regproc('foo'||'bar') wouldn't work; basically the only case that did work without explicit casting was a simple literal constant argument. The lack of field complaints about this suggests that hardly anyone is using these functions, so hopefully fixing it won't cause much of a compatibility problem. They've only been there since 9.4, anyway. Petr Korobeinikov
1 parent efa318b commit ea0d494

File tree

4 files changed

+18
-18
lines changed

4 files changed

+18
-18
lines changed

doc/src/sgml/func.sgml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16173,7 +16173,7 @@ SELECT collation for ('foo' COLLATE "de_DE");
1617316173
<function>to_regoperator</function>, <function>to_regtype</function>,
1617416174
<function>to_regnamespace</function>, and <function>to_regrole</function>
1617516175
functions translate relation, function, operator, type, schema, and role
16176-
names to objects of
16176+
names (given as <type>text</>) to objects of
1617716177
type <type>regclass</>, <type>regproc</>, <type>regprocedure</type>,
1617816178
<type>regoper</>, <type>regoperator</type>, <type>regtype</>,
1617916179
<type>regnamespace</>, and <type>regrole</>

src/backend/utils/adt/regproc.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ regprocin(PG_FUNCTION_ARGS)
161161
Datum
162162
to_regproc(PG_FUNCTION_ARGS)
163163
{
164-
char *pro_name = PG_GETARG_CSTRING(0);
164+
char *pro_name = text_to_cstring(PG_GETARG_TEXT_PP(0));
165165
List *names;
166166
FuncCandidateList clist;
167167

@@ -331,7 +331,7 @@ regprocedurein(PG_FUNCTION_ARGS)
331331
Datum
332332
to_regprocedure(PG_FUNCTION_ARGS)
333333
{
334-
char *pro_name = PG_GETARG_CSTRING(0);
334+
char *pro_name = text_to_cstring(PG_GETARG_TEXT_PP(0));
335335
List *names;
336336
int nargs;
337337
Oid argtypes[FUNC_MAX_ARGS];
@@ -620,7 +620,7 @@ regoperin(PG_FUNCTION_ARGS)
620620
Datum
621621
to_regoper(PG_FUNCTION_ARGS)
622622
{
623-
char *opr_name = PG_GETARG_CSTRING(0);
623+
char *opr_name = text_to_cstring(PG_GETARG_TEXT_PP(0));
624624
List *names;
625625
FuncCandidateList clist;
626626

@@ -797,7 +797,7 @@ regoperatorin(PG_FUNCTION_ARGS)
797797
Datum
798798
to_regoperator(PG_FUNCTION_ARGS)
799799
{
800-
char *opr_name_or_oid = PG_GETARG_CSTRING(0);
800+
char *opr_name_or_oid = text_to_cstring(PG_GETARG_TEXT_PP(0));
801801
Oid result;
802802
List *names;
803803
int nargs;
@@ -1061,7 +1061,7 @@ regclassin(PG_FUNCTION_ARGS)
10611061
Datum
10621062
to_regclass(PG_FUNCTION_ARGS)
10631063
{
1064-
char *class_name = PG_GETARG_CSTRING(0);
1064+
char *class_name = text_to_cstring(PG_GETARG_TEXT_PP(0));
10651065
Oid result;
10661066
List *names;
10671067

@@ -1249,7 +1249,7 @@ regtypein(PG_FUNCTION_ARGS)
12491249
Datum
12501250
to_regtype(PG_FUNCTION_ARGS)
12511251
{
1252-
char *typ_name = PG_GETARG_CSTRING(0);
1252+
char *typ_name = text_to_cstring(PG_GETARG_TEXT_PP(0));
12531253
Oid result;
12541254
int32 typmod;
12551255

@@ -1606,7 +1606,7 @@ regrolein(PG_FUNCTION_ARGS)
16061606
Datum
16071607
to_regrole(PG_FUNCTION_ARGS)
16081608
{
1609-
char *role_name = PG_GETARG_CSTRING(0);
1609+
char *role_name = text_to_cstring(PG_GETARG_TEXT_PP(0));
16101610
Oid result;
16111611
List *names;
16121612

@@ -1727,7 +1727,7 @@ regnamespacein(PG_FUNCTION_ARGS)
17271727
Datum
17281728
to_regnamespace(PG_FUNCTION_ARGS)
17291729
{
1730-
char *nsp_name = PG_GETARG_CSTRING(0);
1730+
char *nsp_name = text_to_cstring(PG_GETARG_TEXT_PP(0));
17311731
Oid result;
17321732
List *names;
17331733

src/include/catalog/catversion.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,6 @@
5353
*/
5454

5555
/* yyyymmddN */
56-
#define CATALOG_VERSION_NO 201601041
56+
#define CATALOG_VERSION_NO 201601051
5757

5858
#endif

src/include/catalog/pg_proc.h

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -177,9 +177,9 @@ DATA(insert OID = 44 ( regprocin PGNSP PGUID 12 1 0 0 0 f f f f t f s s 1
177177
DESCR("I/O");
178178
DATA(insert OID = 45 ( regprocout PGNSP PGUID 12 1 0 0 0 f f f f t f s s 1 0 2275 "24" _null_ _null_ _null_ _null_ _null_ regprocout _null_ _null_ _null_ ));
179179
DESCR("I/O");
180-
DATA(insert OID = 3494 ( to_regproc PGNSP PGUID 12 1 0 0 0 f f f f t f s s 1 0 24 "2275" _null_ _null_ _null_ _null_ _null_ to_regproc _null_ _null_ _null_ ));
180+
DATA(insert OID = 3494 ( to_regproc PGNSP PGUID 12 1 0 0 0 f f f f t f s s 1 0 24 "25" _null_ _null_ _null_ _null_ _null_ to_regproc _null_ _null_ _null_ ));
181181
DESCR("convert proname to regproc");
182-
DATA(insert OID = 3479 ( to_regprocedure PGNSP PGUID 12 1 0 0 0 f f f f t f s s 1 0 2202 "2275" _null_ _null_ _null_ _null_ _null_ to_regprocedure _null_ _null_ _null_ ));
182+
DATA(insert OID = 3479 ( to_regprocedure PGNSP PGUID 12 1 0 0 0 f f f f t f s s 1 0 2202 "25" _null_ _null_ _null_ _null_ _null_ to_regprocedure _null_ _null_ _null_ ));
183183
DESCR("convert proname to regprocedure");
184184
DATA(insert OID = 46 ( textin PGNSP PGUID 12 1 0 0 0 f f f f t f i s 1 0 25 "2275" _null_ _null_ _null_ _null_ _null_ textin _null_ _null_ _null_ ));
185185
DESCR("I/O");
@@ -3483,9 +3483,9 @@ DATA(insert OID = 2214 ( regoperin PGNSP PGUID 12 1 0 0 0 f f f f t f s s 1 0
34833483
DESCR("I/O");
34843484
DATA(insert OID = 2215 ( regoperout PGNSP PGUID 12 1 0 0 0 f f f f t f s s 1 0 2275 "2203" _null_ _null_ _null_ _null_ _null_ regoperout _null_ _null_ _null_ ));
34853485
DESCR("I/O");
3486-
DATA(insert OID = 3492 ( to_regoper PGNSP PGUID 12 1 0 0 0 f f f f t f s s 1 0 2203 "2275" _null_ _null_ _null_ _null_ _null_ to_regoper _null_ _null_ _null_ ));
3486+
DATA(insert OID = 3492 ( to_regoper PGNSP PGUID 12 1 0 0 0 f f f f t f s s 1 0 2203 "25" _null_ _null_ _null_ _null_ _null_ to_regoper _null_ _null_ _null_ ));
34873487
DESCR("convert operator name to regoper");
3488-
DATA(insert OID = 3476 ( to_regoperator PGNSP PGUID 12 1 0 0 0 f f f f t f s s 1 0 2204 "2275" _null_ _null_ _null_ _null_ _null_ to_regoperator _null_ _null_ _null_ ));
3488+
DATA(insert OID = 3476 ( to_regoperator PGNSP PGUID 12 1 0 0 0 f f f f t f s s 1 0 2204 "25" _null_ _null_ _null_ _null_ _null_ to_regoperator _null_ _null_ _null_ ));
34893489
DESCR("convert operator name to regoperator");
34903490
DATA(insert OID = 2216 ( regoperatorin PGNSP PGUID 12 1 0 0 0 f f f f t f s s 1 0 2204 "2275" _null_ _null_ _null_ _null_ _null_ regoperatorin _null_ _null_ _null_ ));
34913491
DESCR("I/O");
@@ -3495,13 +3495,13 @@ DATA(insert OID = 2218 ( regclassin PGNSP PGUID 12 1 0 0 0 f f f f t f s s 1 0
34953495
DESCR("I/O");
34963496
DATA(insert OID = 2219 ( regclassout PGNSP PGUID 12 1 0 0 0 f f f f t f s s 1 0 2275 "2205" _null_ _null_ _null_ _null_ _null_ regclassout _null_ _null_ _null_ ));
34973497
DESCR("I/O");
3498-
DATA(insert OID = 3495 ( to_regclass PGNSP PGUID 12 1 0 0 0 f f f f t f s s 1 0 2205 "2275" _null_ _null_ _null_ _null_ _null_ to_regclass _null_ _null_ _null_ ));
3498+
DATA(insert OID = 3495 ( to_regclass PGNSP PGUID 12 1 0 0 0 f f f f t f s s 1 0 2205 "25" _null_ _null_ _null_ _null_ _null_ to_regclass _null_ _null_ _null_ ));
34993499
DESCR("convert classname to regclass");
35003500
DATA(insert OID = 2220 ( regtypein PGNSP PGUID 12 1 0 0 0 f f f f t f s s 1 0 2206 "2275" _null_ _null_ _null_ _null_ _null_ regtypein _null_ _null_ _null_ ));
35013501
DESCR("I/O");
35023502
DATA(insert OID = 2221 ( regtypeout PGNSP PGUID 12 1 0 0 0 f f f f t f s s 1 0 2275 "2206" _null_ _null_ _null_ _null_ _null_ regtypeout _null_ _null_ _null_ ));
35033503
DESCR("I/O");
3504-
DATA(insert OID = 3493 ( to_regtype PGNSP PGUID 12 1 0 0 0 f f f f t f s s 1 0 2206 "2275" _null_ _null_ _null_ _null_ _null_ to_regtype _null_ _null_ _null_ ));
3504+
DATA(insert OID = 3493 ( to_regtype PGNSP PGUID 12 1 0 0 0 f f f f t f s s 1 0 2206 "25" _null_ _null_ _null_ _null_ _null_ to_regtype _null_ _null_ _null_ ));
35053505
DESCR("convert type name to regtype");
35063506
DATA(insert OID = 1079 ( regclass PGNSP PGUID 12 1 0 0 0 f f f f t f s s 1 0 2205 "25" _null_ _null_ _null_ _null_ _null_ text_regclass _null_ _null_ _null_ ));
35073507
DESCR("convert text to regclass");
@@ -3510,14 +3510,14 @@ DATA(insert OID = 4098 ( regrolein PGNSP PGUID 12 1 0 0 0 f f f f t f s s 1 0
35103510
DESCR("I/O");
35113511
DATA(insert OID = 4092 ( regroleout PGNSP PGUID 12 1 0 0 0 f f f f t f s s 1 0 2275 "4096" _null_ _null_ _null_ _null_ _null_ regroleout _null_ _null_ _null_ ));
35123512
DESCR("I/O");
3513-
DATA(insert OID = 4093 ( to_regrole PGNSP PGUID 12 1 0 0 0 f f f f t f s s 1 0 4096 "2275" _null_ _null_ _null_ _null_ _null_ to_regrole _null_ _null_ _null_ ));
3513+
DATA(insert OID = 4093 ( to_regrole PGNSP PGUID 12 1 0 0 0 f f f f t f s s 1 0 4096 "25" _null_ _null_ _null_ _null_ _null_ to_regrole _null_ _null_ _null_ ));
35143514
DESCR("convert role name to regrole");
35153515

35163516
DATA(insert OID = 4084 ( regnamespacein PGNSP PGUID 12 1 0 0 0 f f f f t f s s 1 0 4089 "2275" _null_ _null_ _null_ _null_ _null_ regnamespacein _null_ _null_ _null_ ));
35173517
DESCR("I/O");
35183518
DATA(insert OID = 4085 ( regnamespaceout PGNSP PGUID 12 1 0 0 0 f f f f t f s s 1 0 2275 "4089" _null_ _null_ _null_ _null_ _null_ regnamespaceout _null_ _null_ _null_ ));
35193519
DESCR("I/O");
3520-
DATA(insert OID = 4086 ( to_regnamespace PGNSP PGUID 12 1 0 0 0 f f f f t f s s 1 0 4089 "2275" _null_ _null_ _null_ _null_ _null_ to_regnamespace _null_ _null_ _null_ ));
3520+
DATA(insert OID = 4086 ( to_regnamespace PGNSP PGUID 12 1 0 0 0 f f f f t f s s 1 0 4089 "25" _null_ _null_ _null_ _null_ _null_ to_regnamespace _null_ _null_ _null_ ));
35213521
DESCR("convert namespace name to regnamespace");
35223522

35233523
DATA(insert OID = 2246 ( fmgr_internal_validator PGNSP PGUID 12 1 0 0 0 f f f f t f s s 1 0 2278 "26" _null_ _null_ _null_ _null_ _null_ fmgr_internal_validator _null_ _null_ _null_ ));

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy