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

union_relations macro unable to union relations with ARRAY on Postgres #857

Open
1 task done
pcreux opened this issue Dec 6, 2023 · 7 comments
Open
1 task done
Labels
bug Something isn't working triage

Comments

@pcreux
Copy link

pcreux commented Dec 6, 2023

Describe the bug

Calling union_relations on relations with an array column generates invalid SQL:

  syntax error at or near "ARRAY"
  cast("my_array" as ARRAY) as "my_array"

Steps to reproduce

  • Create a table with an array of integers or strings:
CREATE TABLE my_table(my_array int[]);
  • Perform an union_relations on that table:
    {% set relations = [
      api.Relation.create(schema='public', identifier='my_table')
      ]
    %}
   {{ dbt_utils.union_relations(relations) }

Expected results

Valid SQL:

--- ...
cast(my_array as int[]) as my_array,
--- ...

Actual results

Invalid SQL:

--- ...
cast(my_array as ARRAY) as my_array,
--- ...

System information

The contents of your packages.yml file:

packages:
  - package: dbt-labs/dbt_utils
    version: 1.1.1

Which database are you using dbt with?

  • postgres

The output of dbt --version:

Core:
  - installed: 1.7.2
  - latest:    1.7.3 - Update available!

  Your version of dbt-core is out of date!
  You can find instructions for upgrading here:
  https://docs.getdbt.com/docs/installation

Plugins:
  - bigquery: 1.7.2 - Up to date!
  - postgres: 1.7.2 - Update available!

Are you interested in contributing the fix?

The code casts using dbt.type_string() or col.data_type. I don't know if there's another attribute that would return the_type[] instead of ARRAY.

@pcreux pcreux added bug Something isn't working triage labels Dec 6, 2023
@rubenvereecken
Copy link

Just ran into the same for a jsonb[] column.

@shayansm2
Copy link

I also had the same problem

@saad-saras
Copy link

Has anyone figured out a solution for this? When I'm trying to union two tables with nested arrays, I'm facing the same issue

@rubenvereecken
Copy link

Turns out this issue has been around for at least 4 years

@nstringham
Copy link

I tried using column_override but I'm still getting the error.

Copy link

This issue has been marked as Stale because it has been open for 180 days with no activity. If you would like the issue to remain open, please comment on the issue or else it will be closed in 7 days.

@github-actions github-actions bot added the Stale label Nov 27, 2024
@nstringham
Copy link

This is still an issue

@github-actions github-actions bot removed the Stale label Nov 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working triage
Projects
None yet
Development

No branches or pull requests

5 participants