@@ -152,6 +152,31 @@ regprocin(PG_FUNCTION_ARGS)
152
152
PG_RETURN_OID (result );
153
153
}
154
154
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
+
155
180
/*
156
181
* regprocout - converts proc OID to "pro_name"
157
182
*/
@@ -502,7 +527,7 @@ regoperin(PG_FUNCTION_ARGS)
502
527
* pg_operator entries in the current search path.
503
528
*/
504
529
names = stringToQualifiedNameList (opr_name_or_oid );
505
- clist = OpernameGetCandidates (names , '\0' );
530
+ clist = OpernameGetCandidates (names , '\0' , false );
506
531
507
532
if (clist == NULL )
508
533
ereport (ERROR ,
@@ -519,6 +544,31 @@ regoperin(PG_FUNCTION_ARGS)
519
544
PG_RETURN_OID (result );
520
545
}
521
546
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
+
522
572
/*
523
573
* regoperout - converts operator OID to "opr_name"
524
574
*/
@@ -558,7 +608,7 @@ regoperout(PG_FUNCTION_ARGS)
558
608
* qualify it.
559
609
*/
560
610
clist = OpernameGetCandidates (list_make1 (makeString (oprname )),
561
- '\0' );
611
+ '\0' , false );
562
612
if (clist != NULL && clist -> next == NULL &&
563
613
clist -> oid == oprid )
564
614
result = pstrdup (oprname );
@@ -872,6 +922,33 @@ regclassin(PG_FUNCTION_ARGS)
872
922
PG_RETURN_OID (result );
873
923
}
874
924
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
+
875
952
/*
876
953
* regclassout - converts class OID to "class_name"
877
954
*/
@@ -1028,11 +1105,34 @@ regtypein(PG_FUNCTION_ARGS)
1028
1105
* Normal case: invoke the full parser to deal with special cases such as
1029
1106
* array syntax.
1030
1107
*/
1031
- parseTypeString (typ_name_or_oid , & result , & typmod );
1108
+ parseTypeString (typ_name_or_oid , & result , & typmod , false );
1032
1109
1033
1110
PG_RETURN_OID (result );
1034
1111
}
1035
1112
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
+
1036
1136
/*
1037
1137
* regtypeout - converts type OID to "typ_name"
1038
1138
*/
@@ -1523,7 +1623,7 @@ parseNameAndArgTypes(const char *string, bool allowNone, List **names,
1523
1623
else
1524
1624
{
1525
1625
/* Use full parser to resolve the type name */
1526
- parseTypeString (typename , & typeid , & typmod );
1626
+ parseTypeString (typename , & typeid , & typmod , false );
1527
1627
}
1528
1628
if (* nargs >= FUNC_MAX_ARGS )
1529
1629
ereport (ERROR ,
0 commit comments