Computing hashes in PostgreSQL for JSONB columns
0
votes
1
answer
2242
views
From PostgreSQL docs :
>
jsonb
does not preserve white space, does not preserve the order of object keys, and does not keep duplicate object keys. If duplicate keys are specified in the input, only the last value is kept.
I have a jsonb
column that contains some data. I extract specific key data (which is also json) and hash it using sha256, something like:
SELECT sha256(to_jsonb(rule_element) :: TEXT :: BYTEA);
Where rule_element
was extracted from the original data. Given that it does not maintain order of keys and the original column of jsonb
may be updated in the future, I do not think it is safe to compute hashes as they might change.
Can I compute consistent hashes for jsonb
columns? (99% Sure you can't, 1% hope to make my work easier)
The hashes would be used for unique identification purposes, basically acting as a unique key for different types of JSON compositions.
Asked by VIAGC
(103 rep)
Jan 17, 2024, 05:27 AM
Last activity: Jan 17, 2024, 11:28 AM
Last activity: Jan 17, 2024, 11:28 AM