-- Testing cross-types compatibility SELECT (0::uint2)::numeric; numeric --------- 0 (1 row) SELECT ('0'::numeric)::uint2; uint2 ------- 0 (1 row) SELECT ('65536'::numeric)::uint2; ERROR: uint2 out of range SELECT (0::uint2)::json; json ------ 0 (1 row) SELECT json_build_object('some', 0::uint2); json_build_object ------------------- {"some" : 0} (1 row) SELECT ('0'::json)::uint2; uint2 ------- 0 (1 row) SELECT (0::uint2)::jsonb; jsonb ------- 0 (1 row) SELECT jsonb_build_object('some', 0::uint2); jsonb_build_object -------------------- {"some": 0} (1 row) SELECT ('0'::jsonb)::uint2; uint2 ------- 0 (1 row) SELECT ('"abc"'::jsonb)::uint2; ERROR: cannot cast jsonb string to type uint2