So, I checked my original code, and I didn't add `::text`, it was actually added by Postgres:
EXPLAIN for: SELECT "user_event".* FROM "user_event" WHERE "user_event"."what" = $1 AND (((parameters ->> 'suggestion_id')::integer) = 119 AND ((parameters ->> 'suggestion_id') IS NOT NULL)) [["what", "suggestion_notification"]]
> EXPLAIN SELECT COUNT(*) FROM "user_event" WHERE ((parameters ->> > 'suggestion_id'::text)::integer = 26) AND what = 'suggestion_notification';
> It's slow. I need to explicitly add the NULL constraint:
Try it like
EXPLAIN SELECT COUNT(*) FROM "user_event" WHERE ((parameters ->> 'suggestion_id'::text) = '26') AND what = 'suggestion_notification';
I don't think we assume that CoerceViaIO is strict, and without that the deduction that the value couldn't be null doesn't hold. In any case you're better off without the runtime type conversion: that isn't doing much for you except raising the odds of getting an error.