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

snapshot with unique key longer than 30 chars fails on duplicate #117

Closed
dubravcik opened this issue Feb 22, 2021 · 4 comments
Closed

snapshot with unique key longer than 30 chars fails on duplicate #117

dubravcik opened this issue Feb 22, 2021 · 4 comments
Labels
bug Something isn't working

Comments

@dubravcik
Copy link
Contributor

dubravcik commented Feb 22, 2021

Hi, I have a snapshot with unique_key on hash and I am getting duplicate error on internal dbt_scd_id in merge phase.

I checked the dbt code and problem is, it converts the id_hash to varchar. SQL Server uses by default 30 (!?wt.f!?) chars if you state varchar without a length.

CONVERT(VARCHAR(32), HashBytes(''MD5'', 
        coalesce(CONVERT(>>>>varchar<<<<, [id_hash], 121), '''')  + ''|'' +     
        coalesce(CONVERT(>>>>varchar<<<<, CONVERT(DATETIME2, ''2021-02-22 19:33:59.020000''), 121), '''') 
    ), 2)

I would probably change it to varchar(max) as it is changed to varchar(32) at the end anyway.

@mikaelene
Copy link
Collaborator

Relates to #108. @dubravcik do you think #118 will solve it?

@dubravcik
Copy link
Contributor Author

I don’t think so, it still uses varchar which defaults to 30 chars. I suggest varchar(max) , I don’t think that it will have a significant performance impact, but I can test it on my data.

@mikaelene
Copy link
Collaborator

Ahh. I’ll change to max. There was also an issue when I tried to cast it as a date before. I somehow missed that it uses the key to.

@mikaelene
Copy link
Collaborator

closed by #118

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants