datafusion
datafusion copied to clipboard
Unparse array_has as = ANY() for PostgreSQL dialect
Is your feature request related to a problem or challenge?
When using the SQL unparser with PostgreSqlDialect, array_has(haystack, needle) is emitted as-is. PostgreSQL does not have an array_has() function, so this produces invalid SQL. The idiomatic Postgres equivalent is needle = ANY(haystack).
Describe the solution you'd like
Add a scalar_function_to_sql_overrides entry in PostgreSqlDialect that converts array_has(haystack, needle) to needle = ANY(haystack) using ast::Expr::AnyOp.
Describe alternatives you've considered
The @> containment operator (haystack @> ARRAY[needle]) is another valid Postgres syntax, but = ANY() is more conventional for single-element checks and maps directly to the AnyOp AST node.
Additional context
N/A