I am looking for a way to create a constraint that will verify the values in a JSONB column are unique, however i need them to also be unique when compared without taking order into account, so JSONB comparison / hashing is not valid for this case.
In order to check if 2 JSONB objects are equal, i check if they contain each other
select t.a @> t.b and t.a <@ t.b
from (
SELECT
'{"foo": 42, "bar": ["value", 5]}'::jsonb as a,
'{"bar": [5, "value"], "foo": 42}'::jsonb as b
) as t
Specifically i am looking for an SQLAlchemy solution, but a raw postgresql solution will probably help a lot.
fooandbarwill be reordered automatically, but I doubt that there is a good solution.