From: Tom Lane Date: Tue, 5 Jan 2016 18:02:43 +0000 (-0500) Subject: Make the to_reg*() functions accept text not cstring. X-Git-Tag: REL9_6_BETA1~901 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=ea0d494dae0d3d6f;p=postgresql 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 --- diff --git a/doc/src/sgml/func.sgml b/doc/src/sgml/func.sgml index 4ce634cc29..a0b42c2ddb 100644 --- a/doc/src/sgml/func.sgml +++ b/doc/src/sgml/func.sgml @@ -16173,7 +16173,7 @@ SELECT collation for ('foo' COLLATE "de_DE"); to_regoperator, to_regtype, to_regnamespace, and to_regrole functions translate relation, function, operator, type, schema, and role - names to objects of + names (given as text) to objects of type regclass, regproc, regprocedure, regoper, regoperator, regtype, regnamespace, and regrole diff --git a/src/backend/utils/adt/regproc.c b/src/backend/utils/adt/regproc.c index 0f17eb8000..394042cbba 100644 --- a/src/backend/utils/adt/regproc.c +++ b/src/backend/utils/adt/regproc.c @@ -161,7 +161,7 @@ regprocin(PG_FUNCTION_ARGS) Datum to_regproc(PG_FUNCTION_ARGS) { - char *pro_name = PG_GETARG_CSTRING(0); + char *pro_name = text_to_cstring(PG_GETARG_TEXT_PP(0)); List *names; FuncCandidateList clist; @@ -331,7 +331,7 @@ regprocedurein(PG_FUNCTION_ARGS) Datum to_regprocedure(PG_FUNCTION_ARGS) { - char *pro_name = PG_GETARG_CSTRING(0); + char *pro_name = text_to_cstring(PG_GETARG_TEXT_PP(0)); List *names; int nargs; Oid argtypes[FUNC_MAX_ARGS]; @@ -620,7 +620,7 @@ regoperin(PG_FUNCTION_ARGS) Datum to_regoper(PG_FUNCTION_ARGS) { - char *opr_name = PG_GETARG_CSTRING(0); + char *opr_name = text_to_cstring(PG_GETARG_TEXT_PP(0)); List *names; FuncCandidateList clist; @@ -797,7 +797,7 @@ regoperatorin(PG_FUNCTION_ARGS) Datum to_regoperator(PG_FUNCTION_ARGS) { - char *opr_name_or_oid = PG_GETARG_CSTRING(0); + char *opr_name_or_oid = text_to_cstring(PG_GETARG_TEXT_PP(0)); Oid result; List *names; int nargs; @@ -1061,7 +1061,7 @@ regclassin(PG_FUNCTION_ARGS) Datum to_regclass(PG_FUNCTION_ARGS) { - char *class_name = PG_GETARG_CSTRING(0); + char *class_name = text_to_cstring(PG_GETARG_TEXT_PP(0)); Oid result; List *names; @@ -1249,7 +1249,7 @@ regtypein(PG_FUNCTION_ARGS) Datum to_regtype(PG_FUNCTION_ARGS) { - char *typ_name = PG_GETARG_CSTRING(0); + char *typ_name = text_to_cstring(PG_GETARG_TEXT_PP(0)); Oid result; int32 typmod; @@ -1606,7 +1606,7 @@ regrolein(PG_FUNCTION_ARGS) Datum to_regrole(PG_FUNCTION_ARGS) { - char *role_name = PG_GETARG_CSTRING(0); + char *role_name = text_to_cstring(PG_GETARG_TEXT_PP(0)); Oid result; List *names; @@ -1727,7 +1727,7 @@ regnamespacein(PG_FUNCTION_ARGS) Datum to_regnamespace(PG_FUNCTION_ARGS) { - char *nsp_name = PG_GETARG_CSTRING(0); + char *nsp_name = text_to_cstring(PG_GETARG_TEXT_PP(0)); Oid result; List *names; diff --git a/src/include/catalog/catversion.h b/src/include/catalog/catversion.h index 0e66e9286b..2c6aa45063 100644 --- a/src/include/catalog/catversion.h +++ b/src/include/catalog/catversion.h @@ -53,6 +53,6 @@ */ /* yyyymmddN */ -#define CATALOG_VERSION_NO 201601041 +#define CATALOG_VERSION_NO 201601051 #endif diff --git a/src/include/catalog/pg_proc.h b/src/include/catalog/pg_proc.h index e5d6c77cec..22d9386ada 100644 --- a/src/include/catalog/pg_proc.h +++ b/src/include/catalog/pg_proc.h @@ -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 DESCR("I/O"); 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_ )); DESCR("I/O"); -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_ )); +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_ )); DESCR("convert proname to regproc"); -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_ )); +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_ )); DESCR("convert proname to regprocedure"); 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_ )); 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 DESCR("I/O"); 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_ )); DESCR("I/O"); -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_ )); +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_ )); DESCR("convert operator name to regoper"); -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_ )); +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_ )); DESCR("convert operator name to regoperator"); 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_ )); 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 DESCR("I/O"); 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_ )); DESCR("I/O"); -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_ )); +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_ )); DESCR("convert classname to regclass"); 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_ )); DESCR("I/O"); 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_ )); DESCR("I/O"); -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_ )); +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_ )); DESCR("convert type name to regtype"); 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_ )); 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 DESCR("I/O"); 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_ )); DESCR("I/O"); -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_ )); +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_ )); DESCR("convert role name to regrole"); 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_ )); DESCR("I/O"); 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_ )); DESCR("I/O"); -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_ )); +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_ )); DESCR("convert namespace name to regnamespace"); 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_ ));