skip to Main Content

I am looking for hash function, that I can use in Postgresql to be more specific in Amazon Aurora Db. The Hash value generated should be of 8 bytes long that can be stored in string field of length 8.

Do we have any such hash function that matches the above mentioned criteria. Any leads on this would be really helpful. Thank you.

2

Answers


  1. You can use the built-in hash function MD5, which produces a 32-character text string.

    Then truncate to 8 bytes by using the substring(string, start_position, length )

    SELECT substring(md5(your_column), 1, 8) AS hash_value FROM your_table;
    
    Login or Signup to reply.
  2. You cannot store 8 bytes as 8 characters. But a bytea would work; for example

    SELECT ('x' || to_hex(hashtextextended('dsadswa', 0)))::bytea;
    
           bytea        
    ════════════════════
     x14862f5b0ca6bca6
    (1 row)
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search