@@ -118,24 +118,15 @@ Datum
118
118
to_regproc (PG_FUNCTION_ARGS )
119
119
{
120
120
char * pro_name = text_to_cstring (PG_GETARG_TEXT_PP (0 ));
121
- List * names ;
122
- FuncCandidateList clist ;
121
+ Datum result ;
123
122
ErrorSaveContext escontext = {T_ErrorSaveContext };
124
123
125
- /*
126
- * Parse the name into components and see if it matches any pg_proc
127
- * entries in the current search path.
128
- */
129
- names = stringToQualifiedNameList (pro_name , (Node * ) & escontext );
130
- if (names == NIL )
131
- PG_RETURN_NULL ();
132
-
133
- clist = FuncnameGetCandidates (names , -1 , NIL , false, false, false, true);
134
-
135
- if (clist == NULL || clist -> next != NULL )
124
+ if (!DirectInputFunctionCallSafe (regprocin , pro_name ,
125
+ InvalidOid , -1 ,
126
+ (Node * ) & escontext ,
127
+ & result ))
136
128
PG_RETURN_NULL ();
137
-
138
- PG_RETURN_OID (clist -> oid );
129
+ PG_RETURN_DATUM (result );
139
130
}
140
131
141
132
/*
@@ -287,31 +278,15 @@ Datum
287
278
to_regprocedure (PG_FUNCTION_ARGS )
288
279
{
289
280
char * pro_name = text_to_cstring (PG_GETARG_TEXT_PP (0 ));
290
- List * names ;
291
- int nargs ;
292
- Oid argtypes [FUNC_MAX_ARGS ];
293
- FuncCandidateList clist ;
281
+ Datum result ;
294
282
ErrorSaveContext escontext = {T_ErrorSaveContext };
295
283
296
- /*
297
- * Parse the name and arguments, look up potential matches in the current
298
- * namespace search list, and scan to see which one exactly matches the
299
- * given argument types. (There will not be more than one match.)
300
- */
301
- if (!parseNameAndArgTypes (pro_name , false,
302
- & names , & nargs , argtypes ,
303
- (Node * ) & escontext ))
284
+ if (!DirectInputFunctionCallSafe (regprocedurein , pro_name ,
285
+ InvalidOid , -1 ,
286
+ (Node * ) & escontext ,
287
+ & result ))
304
288
PG_RETURN_NULL ();
305
-
306
- clist = FuncnameGetCandidates (names , nargs , NIL , false, false, false, true);
307
-
308
- for (; clist ; clist = clist -> next )
309
- {
310
- if (memcmp (clist -> args , argtypes , nargs * sizeof (Oid )) == 0 )
311
- PG_RETURN_OID (clist -> oid );
312
- }
313
-
314
- PG_RETURN_NULL ();
289
+ PG_RETURN_DATUM (result );
315
290
}
316
291
317
292
/*
@@ -552,24 +527,15 @@ Datum
552
527
to_regoper (PG_FUNCTION_ARGS )
553
528
{
554
529
char * opr_name = text_to_cstring (PG_GETARG_TEXT_PP (0 ));
555
- List * names ;
556
- FuncCandidateList clist ;
530
+ Datum result ;
557
531
ErrorSaveContext escontext = {T_ErrorSaveContext };
558
532
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 , (Node * ) & escontext );
564
- if (names == NIL )
533
+ if (!DirectInputFunctionCallSafe (regoperin , opr_name ,
534
+ InvalidOid , -1 ,
535
+ (Node * ) & escontext ,
536
+ & result ))
565
537
PG_RETURN_NULL ();
566
-
567
- clist = OpernameGetCandidates (names , '\0' , true);
568
-
569
- if (clist == NULL || clist -> next != NULL )
570
- PG_RETURN_NULL ();
571
-
572
- PG_RETURN_OID (clist -> oid );
538
+ PG_RETURN_DATUM (result );
573
539
}
574
540
575
541
/*
@@ -728,31 +694,15 @@ Datum
728
694
to_regoperator (PG_FUNCTION_ARGS )
729
695
{
730
696
char * opr_name_or_oid = text_to_cstring (PG_GETARG_TEXT_PP (0 ));
731
- Oid result ;
732
- List * names ;
733
- int nargs ;
734
- Oid argtypes [FUNC_MAX_ARGS ];
697
+ Datum result ;
735
698
ErrorSaveContext escontext = {T_ErrorSaveContext };
736
699
737
- /*
738
- * Parse the name and arguments, look up potential matches in the current
739
- * namespace search list, and scan to see which one exactly matches the
740
- * given argument types. (There will not be more than one match.)
741
- */
742
- if (!parseNameAndArgTypes (opr_name_or_oid , true,
743
- & names , & nargs , argtypes ,
744
- (Node * ) & escontext ))
745
- PG_RETURN_NULL ();
746
-
747
- if (nargs != 2 )
700
+ if (!DirectInputFunctionCallSafe (regoperatorin , opr_name_or_oid ,
701
+ InvalidOid , -1 ,
702
+ (Node * ) & escontext ,
703
+ & result ))
748
704
PG_RETURN_NULL ();
749
-
750
- result = OpernameGetOprid (names , argtypes [0 ], argtypes [1 ]);
751
-
752
- if (!OidIsValid (result ))
753
- PG_RETURN_NULL ();
754
-
755
- PG_RETURN_OID (result );
705
+ PG_RETURN_DATUM (result );
756
706
}
757
707
758
708
/*
@@ -975,25 +925,15 @@ Datum
975
925
to_regclass (PG_FUNCTION_ARGS )
976
926
{
977
927
char * class_name = text_to_cstring (PG_GETARG_TEXT_PP (0 ));
978
- Oid result ;
979
- List * names ;
928
+ Datum result ;
980
929
ErrorSaveContext escontext = {T_ErrorSaveContext };
981
930
982
- /*
983
- * Parse the name into components and see if it matches any pg_class
984
- * entries in the current search path.
985
- */
986
- names = stringToQualifiedNameList (class_name , (Node * ) & escontext );
987
- if (names == NIL )
988
- PG_RETURN_NULL ();
989
-
990
- /* We might not even have permissions on this relation; don't lock it. */
991
- result = RangeVarGetRelid (makeRangeVarFromNameList (names ), NoLock , true);
992
-
993
- if (OidIsValid (result ))
994
- PG_RETURN_OID (result );
995
- else
931
+ if (!DirectInputFunctionCallSafe (regclassin , class_name ,
932
+ InvalidOid , -1 ,
933
+ (Node * ) & escontext ,
934
+ & result ))
996
935
PG_RETURN_NULL ();
936
+ PG_RETURN_DATUM (result );
997
937
}
998
938
999
939
/*
@@ -1128,24 +1068,15 @@ Datum
1128
1068
to_regcollation (PG_FUNCTION_ARGS )
1129
1069
{
1130
1070
char * collation_name = text_to_cstring (PG_GETARG_TEXT_PP (0 ));
1131
- Oid result ;
1132
- List * names ;
1071
+ Datum result ;
1133
1072
ErrorSaveContext escontext = {T_ErrorSaveContext };
1134
1073
1135
- /*
1136
- * Parse the name into components and see if it matches any pg_collation
1137
- * entries in the current search path.
1138
- */
1139
- names = stringToQualifiedNameList (collation_name , (Node * ) & escontext );
1140
- if (names == NIL )
1141
- PG_RETURN_NULL ();
1142
-
1143
- result = get_collation_oid (names , true);
1144
-
1145
- if (OidIsValid (result ))
1146
- PG_RETURN_OID (result );
1147
- else
1074
+ if (!DirectInputFunctionCallSafe (regcollationin , collation_name ,
1075
+ InvalidOid , -1 ,
1076
+ (Node * ) & escontext ,
1077
+ & result ))
1148
1078
PG_RETURN_NULL ();
1079
+ PG_RETURN_DATUM (result );
1149
1080
}
1150
1081
1151
1082
/*
@@ -1278,17 +1209,15 @@ Datum
1278
1209
to_regtype (PG_FUNCTION_ARGS )
1279
1210
{
1280
1211
char * typ_name = text_to_cstring (PG_GETARG_TEXT_PP (0 ));
1281
- Oid result ;
1282
- int32 typmod ;
1212
+ Datum result ;
1283
1213
ErrorSaveContext escontext = {T_ErrorSaveContext };
1284
1214
1285
- /*
1286
- * Invoke the full parser to deal with special cases such as array syntax.
1287
- */
1288
- if (parseTypeString (typ_name , & result , & typmod , (Node * ) & escontext ))
1289
- PG_RETURN_OID (result );
1290
- else
1215
+ if (!DirectInputFunctionCallSafe (regtypein , typ_name ,
1216
+ InvalidOid , -1 ,
1217
+ (Node * ) & escontext ,
1218
+ & result ))
1291
1219
PG_RETURN_NULL ();
1220
+ PG_RETURN_DATUM (result );
1292
1221
}
1293
1222
1294
1223
/*
@@ -1634,23 +1563,15 @@ Datum
1634
1563
to_regrole (PG_FUNCTION_ARGS )
1635
1564
{
1636
1565
char * role_name = text_to_cstring (PG_GETARG_TEXT_PP (0 ));
1637
- Oid result ;
1638
- List * names ;
1566
+ Datum result ;
1639
1567
ErrorSaveContext escontext = {T_ErrorSaveContext };
1640
1568
1641
- names = stringToQualifiedNameList (role_name , (Node * ) & escontext );
1642
- if (names == NIL )
1643
- PG_RETURN_NULL ();
1644
-
1645
- if (list_length (names ) != 1 )
1646
- PG_RETURN_NULL ();
1647
-
1648
- result = get_role_oid (strVal (linitial (names )), true);
1649
-
1650
- if (OidIsValid (result ))
1651
- PG_RETURN_OID (result );
1652
- else
1569
+ if (!DirectInputFunctionCallSafe (regrolein , role_name ,
1570
+ InvalidOid , -1 ,
1571
+ (Node * ) & escontext ,
1572
+ & result ))
1653
1573
PG_RETURN_NULL ();
1574
+ PG_RETURN_DATUM (result );
1654
1575
}
1655
1576
1656
1577
/*
@@ -1759,23 +1680,15 @@ Datum
1759
1680
to_regnamespace (PG_FUNCTION_ARGS )
1760
1681
{
1761
1682
char * nsp_name = text_to_cstring (PG_GETARG_TEXT_PP (0 ));
1762
- Oid result ;
1763
- List * names ;
1683
+ Datum result ;
1764
1684
ErrorSaveContext escontext = {T_ErrorSaveContext };
1765
1685
1766
- names = stringToQualifiedNameList (nsp_name , (Node * ) & escontext );
1767
- if (names == NIL )
1768
- PG_RETURN_NULL ();
1769
-
1770
- if (list_length (names ) != 1 )
1771
- PG_RETURN_NULL ();
1772
-
1773
- result = get_namespace_oid (strVal (linitial (names )), true);
1774
-
1775
- if (OidIsValid (result ))
1776
- PG_RETURN_OID (result );
1777
- else
1686
+ if (!DirectInputFunctionCallSafe (regnamespacein , nsp_name ,
1687
+ InvalidOid , -1 ,
1688
+ (Node * ) & escontext ,
1689
+ & result ))
1778
1690
PG_RETURN_NULL ();
1691
+ PG_RETURN_DATUM (result );
1779
1692
}
1780
1693
1781
1694
/*
0 commit comments