Appearance
HASH
Apply a hashing algorithm to a character string and return a hexadecimal string.
HASH(string [, algorithm ])
- string
Specify a character string that is the input to the function.
- algorithm
Optionally, specify one of the following algorithms. The default is
2
(SHA-2
).Algorithm Mode Output Length (Bits) Output Type 0 MD5 128 VARCHAR(128) 1 SHA-1 160 2 SHA-2 256 3 SHA-2 512
The return type of this function is VARCHAR(128)
.
Examples
For example:
premdb=# select nickname, hash(nickname,2) hashname
from team
where htid <10
order by nickname;
nickname | hashname
-----------+------------------------------------------------------------------
Blues | a87be8077f00caa60dc4522640674d48d898fc6ad747513b137c8754800b5532
Cherries | 4bb92af3df886cdd3dfb96f1341fdec9c8d1ead626fb00bfc9c0f652fe7170ea
Gunners | 3d2424adb81588b55e21cfd2c3edd704a57a0b97006644f6ed18dabcacd30118
Rovers | 8104dacaef7ff8a603b1df60dc3725f17fa822dfcdb9b54f65618c16fe728627
Seasiders | e098d41f26ac73ac9c95589d00de0a243cac8254cbab6f8b7fe54cedbc497e70
Trotters | 3521b2a0a33a5bcc8fcc749c4a8ceb509a5eb0bc1959d4307cf546374cf7c5f2
Tykes | 42f5e399370e0f2fad34deb312a66fa5b0599cd28c382806b530ffcd5cbda58d
Villains | 72c005cb8fad1826419e3f98582d67386682368ad61ff11c1514df48cdff85fb
(8 rows)
premdb=# select hash('We are such stuff as dreams are made on') from sys.const;
hash
------------------------------------------------------------------
ca8e75531ae20c229cb7b6c996c5d2d7a9906f18564f1c60679dc76dddc2d41c
(1 row)
Parent topic:String Functions