@@ -104,14 +104,15 @@ func newCompiledFunctionInternal(
104104
105105 // Then we'll handle the polymorphic types
106106 // https://www.postgresql.org/docs/15/extend-type-system.html#EXTEND-TYPES-POLYMORPHIC
107- functionParameterTypes := fn .GetParameters ()
108- c .callResolved = make ([]* pgtypes.DoltgresType , len (functionParameterTypes )+ 1 )
107+ c .callResolved = make ([]* pgtypes.DoltgresType , len (overload .params .paramTypes )+ 1 )
109108 hasPolymorphicParam := false
110- for i , param := range functionParameterTypes {
109+ for i , param := range overload . params . paramTypes {
111110 if param .IsPolymorphicType () {
112111 // resolve will ensure that the parameter types are valid, so we can just assign them here
113112 hasPolymorphicParam = true
114113 c .callResolved [i ] = originalTypes [i ]
114+ } else if param .ID == pgtypes .Any .ID {
115+ c .callResolved [i ] = originalTypes [i ]
115116 } else if i < len (args ) {
116117 if d , ok := args [i ].Type ().(* pgtypes.DoltgresType ); ok {
117118 // `param` is a default type which does not have type modifier set
@@ -124,7 +125,7 @@ func newCompiledFunctionInternal(
124125 c .callResolved [len (c .callResolved )- 1 ] = returnType
125126 if returnType .IsPolymorphicType () {
126127 if hasPolymorphicParam {
127- c .callResolved [len (c .callResolved )- 1 ] = c .resolvePolymorphicReturnType (functionParameterTypes , originalTypes , returnType )
128+ c .callResolved [len (c .callResolved )- 1 ] = c .resolvePolymorphicReturnType (overload . params . paramTypes , originalTypes , returnType )
128129 } else if c .Name == "array_in" || c .Name == "array_recv" || c .Name == "enum_in" || c .Name == "enum_recv" || c .Name == "anyenum_in" || c .Name == "anyenum_recv" {
129130 // The return type should resolve to the type of OID value passed in as second argument.
130131 // TODO: Possible that the oid type has a special property with polymorphic return types,
@@ -266,26 +267,28 @@ func (c *CompiledFunction) Eval(ctx *sql.Context, row sql.Row) (interface{}, err
266267 var err error
267268 isStrict := c .overload .Function ().IsStrict ()
268269 args := make ([]any , len (c .Arguments ))
270+ exprTypes := make ([]* pgtypes.DoltgresType , len (args ))
269271 for i , arg := range c .Arguments {
270272 args [i ], err = arg .Eval (ctx , row )
271273 if err != nil {
272274 return nil , err
273275 }
274- // TODO: once we remove GMS types from all of our expressions, we can remove this step which ensures the correct type
275- if _ , ok : = arg .Type ().(* pgtypes.DoltgresType ); ! ok {
276+ var ok bool
277+ if exprTypes [ i ] , ok = arg .Type ().(* pgtypes.DoltgresType ); ! ok {
276278 dt , err := pgtypes .FromGmsTypeToDoltgresType (arg .Type ())
277279 if err != nil {
278280 return nil , err
279281 }
280282 args [i ], _ , _ = dt .Convert (ctx , args [i ])
283+ exprTypes [i ] = dt
281284 }
282285 if args [i ] == nil && isStrict {
283286 return nil , nil
284287 }
285288 }
286289
287290 if len (c .overload .casts ) > 0 {
288- targetParamTypes := c .overload .Function (). GetParameters ()
291+ targetParamTypes := c .overload .params . paramTypes
289292 for i , arg := range args {
290293 // For variadic params, we need to identify the corresponding target type
291294 var targetType * pgtypes.DoltgresType
@@ -320,8 +323,12 @@ func (c *CompiledFunction) Eval(ctx *sql.Context, row sql.Row) (interface{}, err
320323 return f .Callable (ctx )
321324 case Function1 :
322325 return f .Callable (ctx , ([2 ]* pgtypes.DoltgresType )(c .callResolved ), args [0 ])
326+ case Function1N :
327+ return f .Callable (ctx , c .callResolved , args [0 ], args [1 :])
323328 case Function2 :
324329 return f .Callable (ctx , ([3 ]* pgtypes.DoltgresType )(c .callResolved ), args [0 ], args [1 ])
330+ case Function2N :
331+ return f .Callable (ctx , c .callResolved , args [0 ], args [1 ], args [2 :])
325332 case Function3 :
326333 return f .Callable (ctx , ([4 ]* pgtypes.DoltgresType )(c .callResolved ), args [0 ], args [1 ], args [2 ])
327334 case Function4 :
0 commit comments