1

There is a table, which has metadata jsonb field. I created a partial index where (metadata->>'processed')::boolean is FALSE.

I can not clarify, will it work only when {'processed': 'false'}, or also for case where is no processed key. Will this index also work for record with no key as {} for example?

1 Answer 1

1

This index will only cover rows that have a key called "processed" of which the value is "false", 0 or any other literal that can be cast to boolean.

I consider such an index problematic because if someone tries to insert a "metadata" field where "processed" equals "sheep", for instance, then the insert operation will fail because the expression "sheep" cannot be evaluated as boolean.

I think that indexes are not supposed to act as check constraints because it can cause a lot of confusion.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.