You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Potentially Overly-Stringent Type Checking for array_position #9093
This query: SELECT array_position(a, 1) FROM test will fail if a is a list of int32s, due to Error: Plan("array_position received incompatible types: '[Int32, Int64]'.").
I understand that the value to find couldn't be found if 1 was actually a number bigger than an i32 could hold, but it seems to me this should try to work, then fail in that case.
I'd expect array_position to give a best effort to find the query value and fail if the passed value is incompatible due to its magnitude not immediately by its type.
@Weijun-H I think in this case we should convert int32 list to int64 list.
If we got inconsistent types for array_position, we should try type coercion first, if fails, it should be an error.
I'm not sure how duckdb handle this internally. But, they have the same behavior if you convert them to consistent types.
select list_position([1.1, 3.0], CAST(3 as INT)); convert CAST(3 as INT) into 3.0 select list_position([1, 3], 3.0); convert [1,3] to [1.0, 3.0] SELECT list_position([1, 2], cast(1 as FLOAT8)); convert [1, 2] to [1.0, 2.0]
Activity
Weijun-H commentedon Feb 1, 2024
Thank you, @tshauck, for your report. You have made a nice catch. The issue is caused by:
It does not consider similar types with different magnitudes.
And DuckDB can accept
jayzhan211 commentedon Feb 1, 2024
@Weijun-H I think in this case we should convert int32 list to int64 list.
If we got inconsistent types for
array_position, we should try type coercion first, if fails, it should be an error.I'm not sure how duckdb handle this internally. But, they have the same behavior if you convert them to consistent types.
select list_position([1.1, 3.0], CAST(3 as INT));convertCAST(3 as INT)into 3.0select list_position([1, 3], 3.0);convert[1,3]to[1.0, 3.0]SELECT list_position([1, 2], cast(1 as FLOAT8));convert[1, 2]to[1.0, 2.0]Probably changing
to ArrayAndElement fix this issue
Weijun-H commentedon Feb 1, 2024
Yes, I think so. We could extend
ArrayAndElementafter #5340