Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

md5 in bigquery

In BigQuery, I'm using md5 function as:

select md5('<<some string>>') as hashed

which always returns "==" in the last of the letter like:

R7zlx09Yn0hn29V+nKn4CA==    

Why does '==' always come with it?

like image 426
Keisuke Nagakawa 永川 圭介 Avatar asked Jan 29 '19 07:01

Keisuke Nagakawa 永川 圭介


People also ask

What is MD5 in SQL?

The MySQL MD5 function is used to return an MD5 128-bit checksum representation of a string. The MD5 message-digest algorithm is a widely used hash function producing a 128-bit hash value. The value returned by the MD5 function is a binary string of 32 hexadecimal digits, or NULL if the argument was NULL.

What is Farm fingerprint?

FARM_FINGERPRINT(value) Description. Computes the fingerprint of the STRING or BYTES input using the Fingerprint64 function from the open-source FarmHash library. The output of this function for a particular input will never change.

What is the difference between MD5 and sha256?

The MD5 algorithm produces a 128-bit output, which is expressed as a 32 characters hexadecimal. The SHA-256 algorithm is twice longer, with 64 hexadecimal characters for 256-bits.

What is safe cast in BigQuery?

Most data types can be cast from one type to another with the CAST function. When using CAST , a query can fail if BigQuery is unable to perform the cast. If you want to protect your queries from these types of errors, you can use SAFE_CAST .


1 Answers

You need to use TO_HEX to get the representation you want as md5 returns BYTES and you need strings:

TO_HEX: Converts a sequence of BYTES into a hexadecimal STRING. Converts each byte in the STRING as two hexadecimal characters in the range (0..9, a..f).

select TO_HEX(md5('123456')) as hashed

returns:

e10adc3949ba59abbe56e057f20f883e
like image 152
Pentium10 Avatar answered Oct 12 '22 08:10

Pentium10