8
8
*
9
9
*
10
10
* IDENTIFICATION
11
- * $Header: /cvsroot/pgsql/src/backend/parser/parse_func.c,v 1.69 2000/02/15 03:37:47 thomas Exp $
11
+ * $Header: /cvsroot/pgsql/src/backend/parser/parse_func.c,v 1.70 2000/02/20 06:35:08 tgl Exp $
12
12
*
13
13
*-------------------------------------------------------------------------
14
14
*/
@@ -45,14 +45,13 @@ static Oid **argtype_inherit(int nargs, Oid *oid_array);
45
45
46
46
static int find_inheritors (Oid relid , Oid * * supervec );
47
47
static CandidateList func_get_candidates (char * funcname , int nargs );
48
- static bool
49
- func_get_detail (char * funcname ,
50
- int nargs ,
51
- Oid * oid_array ,
52
- Oid * funcid , /* return value */
53
- Oid * rettype , /* return value */
54
- bool * retset , /* return value */
55
- Oid * * true_typeids );
48
+ static bool func_get_detail (char * funcname ,
49
+ int nargs ,
50
+ Oid * oid_array ,
51
+ Oid * funcid , /* return value */
52
+ Oid * rettype , /* return value */
53
+ bool * retset , /* return value */
54
+ Oid * * true_typeids );
56
55
static Oid * * gen_cross_product (InhPaths * arginh , int nargs );
57
56
static void make_arguments (ParseState * pstate ,
58
57
int nargs ,
@@ -228,10 +227,11 @@ agg_select_candidate(Oid typeid, CandidateList candidates)
228
227
}
229
228
}
230
229
/* otherwise, don't bother keeping this one around... */
231
- else if (last_candidate != NULL )
232
- last_candidate -> next = NULL ;
233
230
}
234
231
232
+ if (last_candidate ) /* terminate rebuilt list */
233
+ last_candidate -> next = NULL ;
234
+
235
235
return ((ncandidates == 1 ) ? candidates -> args [0 ] : 0 );
236
236
} /* agg_select_candidate() */
237
237
@@ -559,8 +559,8 @@ ParseFuncOrColumn(ParseState *pstate, char *funcname, List *fargs,
559
559
}
560
560
561
561
/* Most of the rest of the parser just assumes that functions do not
562
- * have more than FUNC_MAX_ARGS parameters. We have to test here to protect
563
- * against array overruns, etc.
562
+ * have more than FUNC_MAX_ARGS parameters. We have to test here
563
+ * to protect against array overruns, etc.
564
564
*/
565
565
if (nargs >= FUNC_MAX_ARGS )
566
566
elog (ERROR , "Cannot pass more than %d arguments to a function" ,
@@ -892,23 +892,27 @@ func_select_candidate(int nargs,
892
892
if ((nmatch + nident ) == nargs )
893
893
return current_candidate -> args ;
894
894
895
+ /* take this one as the best choice so far? */
895
896
if ((nmatch > nbestMatch ) || (last_candidate == NULL ))
896
897
{
897
898
nbestMatch = nmatch ;
898
899
candidates = current_candidate ;
899
900
last_candidate = current_candidate ;
900
901
ncandidates = 1 ;
901
902
}
903
+ /* no worse than the last choice, so keep this one too? */
902
904
else if (nmatch == nbestMatch )
903
905
{
904
906
last_candidate -> next = current_candidate ;
905
907
last_candidate = current_candidate ;
906
908
ncandidates ++ ;
907
909
}
908
- else
909
- last_candidate -> next = NULL ;
910
+ /* otherwise, don't bother keeping this one... */
910
911
}
911
912
913
+ if (last_candidate ) /* terminate rebuilt list */
914
+ last_candidate -> next = NULL ;
915
+
912
916
if (ncandidates == 1 )
913
917
return candidates -> args ;
914
918
@@ -922,6 +926,7 @@ func_select_candidate(int nargs,
922
926
{
923
927
slot_category = INVALID_TYPE ;
924
928
slot_type = InvalidOid ;
929
+ last_candidate = NULL ;
925
930
for (current_candidate = candidates ;
926
931
current_candidate != NULL ;
927
932
current_candidate = current_candidate -> next )
@@ -935,26 +940,39 @@ func_select_candidate(int nargs,
935
940
slot_category = current_category ;
936
941
slot_type = current_type ;
937
942
}
938
- else if ((current_category != slot_category )
939
- && IS_BUILTIN_TYPE (current_type ))
943
+ else if (current_category != slot_category )
944
+ {
945
+ /* punt if more than one category for this slot */
940
946
return NULL ;
947
+ }
941
948
else if (current_type != slot_type )
942
949
{
943
950
if (IsPreferredType (slot_category , current_type ))
944
951
{
945
952
slot_type = current_type ;
953
+ /* forget all previous candidates */
946
954
candidates = current_candidate ;
955
+ last_candidate = current_candidate ;
947
956
}
948
957
else if (IsPreferredType (slot_category , slot_type ))
949
- candidates -> next = current_candidate -> next ;
958
+ {
959
+ /* forget this candidate */
960
+ if (last_candidate )
961
+ last_candidate -> next = current_candidate -> next ;
962
+ else
963
+ candidates = current_candidate -> next ;
964
+ }
965
+ else
966
+ last_candidate = current_candidate ;
967
+ }
968
+ else
969
+ {
970
+ /* keep this candidate */
971
+ last_candidate = current_candidate ;
950
972
}
951
973
}
952
-
953
- if (slot_type != InvalidOid )
954
- input_typeids [i ] = slot_type ;
955
- }
956
- else
957
- {
974
+ if (last_candidate ) /* terminate rebuilt list */
975
+ last_candidate -> next = NULL ;
958
976
}
959
977
}
960
978
0 commit comments