Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix(redshift): don't transform multi-arg DISTINCT clause #3079

Merged
merged 1 commit into from
Mar 4, 2024

Conversation

georgesittas
Copy link
Collaborator

Redshift's aggregation function syntax generally expects [ DISTINCT | ALL ] expression, but LISTAGG is an exception: [DISTINCT] aggregate_expression [, 'delimiter' ].

I didn't address this as a special case, but rather made it so that Redshift doesn't transpile multi-arg DISTINCT expressions at all. The reason is that I played around and realized that Redshift probably doesn't support tuples ("records"?) in that context, so transpiling a query with a multi-arg DISTINCT expression to Redshift would yield invalid SQL anyway:

-- ERROR: could not identify an equality operator for type record
WITH tbl AS (
  SELECT 1 AS id, 'eggy' AS name UNION ALL SELECT NULL AS id, 'jake' AS name
)
SELECT COUNT(
  DISTINCT CASE WHEN id IS NULL THEN NULL WHEN name IS NULL THEN NULL ELSE (id, name) END
) AS cnt
FROM tbl

References:

@georgesittas georgesittas merged commit 0ebce40 into main Mar 4, 2024
5 checks passed
@georgesittas georgesittas deleted the jo/redshift_multi_arg_distinct_fix branch March 4, 2024 20:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants