How are AND expressions evaluated?

Hi,

I have discovered a weird case that I do not really understand: I have a table with a json column which contains objects with mixed values. So a property could be a string or number or whatever.

Therefore I use the following query for numbers:

SELECT * FROM "TestEntity" WHERE ((json_typeof("Json"->'mixed') = 'number' AND ("Json"->>'mixed')::numeric > 5));

but this does not work for booleans. I get the following error: ERROR: invalid input syntax for type boolean: "8"

SELECT * FROM "TestEntity" WHERE ((json_typeof("Json"->'mixed') = 'boolean' AND ("Json"->>'mixed')::boolean = true));

It seems for me that in the second case the right side is also evaluated. I changed it to

SELECT * FROM "TestEntity" WHERE (CASE WHEN json_typeof("Json"->'mixed') = 'boolean' THEN ("Json"->>'mixed')::boolean = true ELSE FALSE END);

But I don't get it.