Sample Header Ad - 728x90

Checksum algorithm for multiple rows

0 votes
0 answers
303 views
I am looking for a fast checksum function to be used in postgres and thought about Adler-32 and crc32c. Postgres don't seem to have such functions implemented by default. The only way i found to implement a hashfunction was like following: SELECT ('x' || encode(digest(column, 'method'), 'hex'))::bit(32)::bigint FROM table The postgres documentation says that there are all openssl functions supported. Unfortunatly, none of the algorithms above are included. Can someone with more experience help me? My goal is to calculate one checksum of multiple rows which only goal is to be used as integrity check of a subset of data. The column in question contains data of type 'TEXT' To clarify my question, here is an example of the table, the expected usage and outcome.
`sql
Example Table:
id |  col | col_2
----------------
1  |'some'| 100
2  |'rndm'|  90
3  |'data'| 400
4  |  'in'|  50
5  |'here'| 600
.
.
.
`
`
Query:
SELECT COUNT(*) as amount, checksum_function(col) as checksum FROM table;
`
`
Expected result:
amount | checksum
-----------------
   20  | hw101h10
` The datatype of the checksum is irrelevant.
Asked by Yuki (41 rep)
Jun 25, 2023, 06:22 PM
Last activity: Jun 26, 2023, 06:14 AM