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

generate_surrogate_key fails on SQL Server with one field #827

Closed
jlkravitz opened this issue Aug 28, 2023 · 6 comments
Closed

generate_surrogate_key fails on SQL Server with one field #827

jlkravitz opened this issue Aug 28, 2023 · 6 comments
Labels

Comments

@jlkravitz
Copy link

The culprit line is here: https://github.com/dbt-labs/dbt-utils/blob/6ba7b660b1d1b4e3b41cb0cf6c3c0e4a70ae54e4/macros/sql/generate_surrogate_key.sql#L27C35-L27C35

select a, b, c, d, {{ dbt_utils.generate_surrogate_key(["a"]) }}
from my_table

results in error

('42000', '[42000] [Microsoft][ODBC Driver 18 for SQL Server][SQL Server]The concat function requires 2 to 254 arguments. (189) (SQLMoreResults)')```

I would expect this not to error.
@vinit2107
Copy link

vinit2107 commented Sep 10, 2023

Hi @jlkravitz ,
The issue is because of this code.

{% macro sqlserver__concat(fields) -%}
    concat({{ fields|join(', ') }})
{%- endmacro %}

You will need to add length validations here and remove concat if the length = 1 or add an empty string to the list (I prefer this). Happy to contribute if you want me to work on it, or you can take it forward 🙂.

@jlkravitz
Copy link
Author

Oh great! I'm happy to take a stab at it.

@vinit2107 Just out of curiosity as I learn this codebase, where can I find the code that dispatches this call to concat to its SQL-backend specific implementation (e.g., SQL Server)?

@vinit2107
Copy link

vinit2107 commented Sep 15, 2023

Hi @jlkravitz ,
Sorry for the delay. You can find the code in dbt-core here.

@bleiho-oc
Copy link

Hi all, same error for the Micosoft Fabric Adapter.

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 Jul 13, 2024
Copy link

Although we are closing this issue as stale, it's not gone forever. Issues can be reopened if there is renewed community interest. Just add a comment to notify the maintainers.

@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Jul 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants