@@ -152,6 +152,31 @@ regprocin(PG_FUNCTION_ARGS)
152152 PG_RETURN_OID (result );
153153}
154154
155+ /*
156+ * to_regproc - converts "proname" to proc OID
157+ *
158+ * If the name is not found, we return NULL.
159+ */
160+ Datum
161+ to_regproc (PG_FUNCTION_ARGS )
162+ {
163+ char * pro_name = PG_GETARG_CSTRING (0 );
164+ List * names ;
165+ FuncCandidateList clist ;
166+
167+ /*
168+ * Parse the name into components and see if it matches any pg_proc entries
169+ * in the current search path.
170+ */
171+ names = stringToQualifiedNameList (pro_name );
172+ clist = FuncnameGetCandidates (names , -1 , NIL , false, false, true);
173+
174+ if (clist == NULL || clist -> next != NULL )
175+ PG_RETURN_NULL ();
176+
177+ PG_RETURN_OID (clist -> oid );
178+ }
179+
155180/*
156181 * regprocout - converts proc OID to "pro_name"
157182 */
@@ -502,7 +527,7 @@ regoperin(PG_FUNCTION_ARGS)
502527 * pg_operator entries in the current search path.
503528 */
504529 names = stringToQualifiedNameList (opr_name_or_oid );
505- clist = OpernameGetCandidates (names , '\0' );
530+ clist = OpernameGetCandidates (names , '\0' , false );
506531
507532 if (clist == NULL )
508533 ereport (ERROR ,
@@ -519,6 +544,31 @@ regoperin(PG_FUNCTION_ARGS)
519544 PG_RETURN_OID (result );
520545}
521546
547+ /*
548+ * to_regoper - converts "oprname" to operator OID
549+ *
550+ * If the name is not found, we return NULL.
551+ */
552+ Datum
553+ to_regoper (PG_FUNCTION_ARGS )
554+ {
555+ char * opr_name = PG_GETARG_CSTRING (0 );
556+ List * names ;
557+ FuncCandidateList clist ;
558+
559+ /*
560+ * Parse the name into components and see if it matches any pg_operator
561+ * entries in the current search path.
562+ */
563+ names = stringToQualifiedNameList (opr_name );
564+ clist = OpernameGetCandidates (names , '\0' , true);
565+
566+ if (clist == NULL || clist -> next != NULL )
567+ PG_RETURN_NULL ();
568+
569+ PG_RETURN_OID (clist -> oid );
570+ }
571+
522572/*
523573 * regoperout - converts operator OID to "opr_name"
524574 */
@@ -558,7 +608,7 @@ regoperout(PG_FUNCTION_ARGS)
558608 * qualify it.
559609 */
560610 clist = OpernameGetCandidates (list_make1 (makeString (oprname )),
561- '\0' );
611+ '\0' , false );
562612 if (clist != NULL && clist -> next == NULL &&
563613 clist -> oid == oprid )
564614 result = pstrdup (oprname );
@@ -872,6 +922,33 @@ regclassin(PG_FUNCTION_ARGS)
872922 PG_RETURN_OID (result );
873923}
874924
925+ /*
926+ * to_regclass - converts "classname" to class OID
927+ *
928+ * If the name is not found, we return NULL.
929+ */
930+ Datum
931+ to_regclass (PG_FUNCTION_ARGS )
932+ {
933+ char * class_name = PG_GETARG_CSTRING (0 );
934+ Oid result ;
935+ List * names ;
936+
937+ /*
938+ * Parse the name into components and see if it matches any pg_class entries
939+ * in the current search path.
940+ */
941+ names = stringToQualifiedNameList (class_name );
942+
943+ /* We might not even have permissions on this relation; don't lock it. */
944+ result = RangeVarGetRelid (makeRangeVarFromNameList (names ), NoLock , true);
945+
946+ if (OidIsValid (result ))
947+ PG_RETURN_OID (result );
948+ else
949+ PG_RETURN_NULL ();
950+ }
951+
875952/*
876953 * regclassout - converts class OID to "class_name"
877954 */
@@ -1028,11 +1105,34 @@ regtypein(PG_FUNCTION_ARGS)
10281105 * Normal case: invoke the full parser to deal with special cases such as
10291106 * array syntax.
10301107 */
1031- parseTypeString (typ_name_or_oid , & result , & typmod );
1108+ parseTypeString (typ_name_or_oid , & result , & typmod , false );
10321109
10331110 PG_RETURN_OID (result );
10341111}
10351112
1113+ /*
1114+ * to_regtype - converts "typename" to type OID
1115+ *
1116+ * If the name is not found, we return NULL.
1117+ */
1118+ Datum
1119+ to_regtype (PG_FUNCTION_ARGS )
1120+ {
1121+ char * typ_name = PG_GETARG_CSTRING (0 );
1122+ Oid result ;
1123+ int32 typmod ;
1124+
1125+ /*
1126+ * Invoke the full parser to deal with special cases such as array syntax.
1127+ */
1128+ parseTypeString (typ_name , & result , & typmod , true);
1129+
1130+ if (OidIsValid (result ))
1131+ PG_RETURN_OID (result );
1132+ else
1133+ PG_RETURN_NULL ();
1134+ }
1135+
10361136/*
10371137 * regtypeout - converts type OID to "typ_name"
10381138 */
@@ -1523,7 +1623,7 @@ parseNameAndArgTypes(const char *string, bool allowNone, List **names,
15231623 else
15241624 {
15251625 /* Use full parser to resolve the type name */
1526- parseTypeString (typename , & typeid , & typmod );
1626+ parseTypeString (typename , & typeid , & typmod , false );
15271627 }
15281628 if (* nargs >= FUNC_MAX_ARGS )
15291629 ereport (ERROR ,
0 commit comments