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

[Feature] Support contextual table aliasing #199

Open
3 tasks done
colin-rogers-dbt opened this issue May 7, 2024 · 5 comments
Open
3 tasks done

[Feature] Support contextual table aliasing #199

colin-rogers-dbt opened this issue May 7, 2024 · 5 comments
Labels
empty Issues related to the --empty CLI flag enhancement New feature or request

Comments

@colin-rogers-dbt
Copy link
Contributor

colin-rogers-dbt commented May 7, 2024

Is this your first time submitting a feature request?

  • I have read the expectations for open source contributors
  • I have searched the existing issues, and I could not find an existing issue for this feature
  • I am requesting a straightforward extension of existing dbt-adapter functionality, rather than a Big Idea better suited to a discussion

Describe the feature

Follow up from: #124

Currently in databases like postgres (at least pre v16) we attempt to inject subqueries with aliases. This can create a poor user experience as when they write something like:

select * from {{ source('my_table') }} as my_source where x=y 

and run with --empty, we produce something like:

select * from {{ source('my_table') }} as _dbt_limit_subq as my_source where x=y 

The duplicate aliases are invalid sql.

The challenge is that in order to know whether the ref already has an alias.

Describe alternatives you've considered

No response

Who will this benefit?

No response

Are you interested in contributing this feature?

No response

Anything else?

No response

@igorvoltaic
Copy link

igorvoltaic commented Sep 1, 2024

To anyone searching for a quick short term solution:
We used a dirty hack to run our pipelines with --empty. We parse our sql after it compiles here and remove double aliases where it breaks our code.

@gajanand-jm
Copy link

facing the same issue

any solution or progress here? we are planning to use --empty for CI

@dbeatty10 dbeatty10 added the empty Issues related to the --empty CLI flag label Sep 26, 2024
@michael-robbins-seek
Copy link

michael-robbins-seek commented Nov 14, 2024

We ended up wrapping some of our references that had an alias with parenthesis, we're using the dbt Athena plugin and it seems to be ok (albeit hacky).

Eg

SELECT *
FROM ({{ source("my_schema", "my_table") }}) as foo

Which renders out as:

SELECT *
FROM ((select * from my_schema.my_table limit 0) as _dbt_injected_alias) as foo

@developmentalmadness
Copy link

developmentalmadness commented Nov 21, 2024

I'm running into the issue w/ dbt-databricks 1.8.7 (dbt-core 1.8.8). What I don't understand is why this needs an alias at all? If platforms like postgres require an alias, then won't the model already be written with an alias? Otherwise, it seems the model wouldn't work under normal conditions.

UDPATE: I now realize this was for subqueries and that models written for a single table will often not use an alias. For some reason my brain filtered out "subqueries" and I inferred "all tables".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
empty Issues related to the --empty CLI flag enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

7 participants