Hash functions

GoogleSQL for BigQuery supports the following hash functions.

Function list

NameSummary
FARM_FINGERPRINT Computes the fingerprint of aSTRING orBYTES value, using the FarmHash Fingerprint64 algorithm.
MD5 Computes the hash of aSTRING orBYTES value, using the MD5 algorithm.
SHA1 Computes the hash of aSTRING orBYTES value, using the SHA-1 algorithm.
SHA256 Computes the hash of aSTRING orBYTES value, using the SHA-256 algorithm.
SHA512 Computes the hash of aSTRING orBYTES value, using the SHA-512 algorithm.

FARM_FINGERPRINT

FARM_FINGERPRINT(value)

Description

Computes the fingerprint of theSTRING orBYTES input using theFingerprint64 function from theopen-source FarmHash library. The outputof this function for a particular input will never change.

Return type

INT64

Examples

WITHexampleAS(SELECT1ASx,"foo"ASy,trueASzUNIONALLSELECT2ASx,"apple"ASy,falseASzUNIONALLSELECT3ASx,""ASy,trueASz)SELECT*,FARM_FINGERPRINT(CONCAT(CAST(xASSTRING),y,CAST(zASSTRING)))ASrow_fingerprintFROMexample;/*---+-------+-------+----------------------+ | x | y     | z     | row_fingerprint      | +---+-------+-------+----------------------+ | 1 | foo   | true  | -1541654101129638711 | | 2 | apple | false | 2794438866806483259  | | 3 |       | true  | -4880158226897771312 | +---+-------+-------+----------------------*/

MD5

MD5(input)

Description

Computes the hash of the input using theMD5 algorithm. The input can either beSTRING orBYTES. The string version treats the input as an array of bytes.

This function returns 16 bytes.

Warning: MD5 is no longer considered secure.For increased security use another hashing function.

Return type

BYTES

Example

SELECTMD5("Hello World")asmd5;-- Note that the result of MD5 is of type BYTES, displayed as a base64-encoded string./*--------------------------+ | md5                      | +--------------------------+ | sQqNsWTgdUEFt6mb5y4/5Q== | +--------------------------*/

SHA1

SHA1(input)

Description

Computes the hash of the input using theSHA-1 algorithm. The input can either beSTRING orBYTES. The string version treats the input as an array of bytes.

This function returns 20 bytes.

Warning: SHA1 is no longer considered secure.For increased security, use another hashing function.

Return type

BYTES

Example

SELECTSHA1("Hello World")assha1;-- Note that the result of SHA1 is of type BYTES, displayed as a base64-encoded string./*------------------------------+ | sha1                         | +------------------------------+ | Ck1VqNd45QIvq3AZd8XYQLvEhtA= | +------------------------------*/

SHA256

SHA256(input)

Description

Computes the hash of the input using theSHA-256 algorithm. The input can either beSTRING orBYTES. The string version treats the input as an array of bytes.

This function returns 32 bytes.

Return type

BYTES

Example

SELECTSHA256("Hello World")assha256;

SHA512

SHA512(input)

Description

Computes the hash of the input using theSHA-512 algorithm. The input can either beSTRING orBYTES. The string version treats the input as an array of bytes.

This function returns 64 bytes.

Return type

BYTES

Example

SELECTSHA512("Hello World")assha512;

Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2025-11-24 UTC.