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

BINARY_CHECKSUM() #1340

Open
Aly071194 opened this issue Sep 17, 2024 · 1 comment
Open

BINARY_CHECKSUM() #1340

Aly071194 opened this issue Sep 17, 2024 · 1 comment

Comments

@Aly071194
Copy link

Hi,

Good day!

I'm currently developing a counterpart script in Snowflake for SQL Server's BINARY_CHECKSUM. Could you please explain how the BINARY_CHECKSUM() function works? Are there any internal functions involved? Additionally, is it possible to use a mathematical formula as an alternative to BINARY_CHECKSUM?

Thank you.

@kfrural
Copy link

kfrural commented Sep 23, 2024

Functionality of BINARY_CHECKSUM()

Calculates a binary checksum value over a row or list of expressions
Returns the same value for a row as long as it isn't modified later
Satisfies hash function properties:
    Same output for equal inputs 
    Output changes if input changes 

Key Characteristics

Ignores columns of non-comparable data types in computation
Supports varbinary(max) of any length and nvarchar(max) up to 255 characters
More precise than CHECKSUM() but with higher computational overhead
May have occasional collisions, so should only be used if application can tolerate undetected changes 

Alternatives

HASHBYTES() is more precise but has additional overhead
Snowflake standard hash functions like SHA256() can be used as alternatives

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

No branches or pull requests

2 participants