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

Trino - when matched ambiguous column when using a function #4595

Closed
MikeWallis42 opened this issue Jan 10, 2025 · 0 comments · Fixed by #4596
Closed

Trino - when matched ambiguous column when using a function #4595

MikeWallis42 opened this issue Jan 10, 2025 · 0 comments · Fixed by #4596

Comments

@MikeWallis42
Copy link
Contributor

  • Read dialect Trino
  • Write dialect Trino
  • Still exists in main

Fully reproducible code snippet

MERGE INTO table_a AS target USING(
  SELECT
    pk,
    my_array
  FROM table_b
) AS source ON source.pk = target.pk
WHEN MATCHED THEN UPDATE SET target.my_array = ARRAY_DISTINCT(CONCAT(source.my_array, target.my_array))
WHEN NOT MATCHED THEN INSERT (pk, my_array)
VALUES (
  source.pk,
  source.my_array
)

As the WHEN MATCHED is a function then this should be possible but there's a transformation applied that strips out the table aliases in the THEN part.
This then leads us to an ambiguous column error as target.my_array is transformed to just my_array.

Might a solution be to also consider if the column's parent is a function? In which case if the merge target is referenced then it is to remove ambiguity.
I'll raise a PR with such a solution shortly and will await comments.

Official Documentation
Please include links to official SQL documentation related to your issue.

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 a pull request may close this issue.

1 participant