How to md5 all columns regardless of type

前端 未结 4 2168
抹茶落季
抹茶落季 2021-02-08 11:40

I would like to create a sql query (or plpgsql) that will md5() all given rows regardless of type. However, below, if one is null then the hash is null:

UPDATE t         


        
4条回答
  •  無奈伤痛
    2021-02-08 12:00

    Have you tried using CONCAT()? I just tried in my PG 9.1 install:

    SELECT CONCAT('aaaa',1111,'bbbb');     => aaaa1111bbbb
    SELECT CONCAT('aaaa',null,'bbbb');     => aaaabbbb
    

    Therefore, you can try:

    SELECT MD5(CONCAT(column1, column2, column3, column_n))    => md5_hash string here
    

提交回复
热议问题