datafusion icon indicating copy to clipboard operation
datafusion copied to clipboard

Unparse array_has as = ANY() for PostgreSQL dialect

Open vimeh opened this issue 9 months ago • 0 comments

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

vimeh avatar Mar 02 '26 18:03 vimeh