Skip to content

Typed exclusion-constraint filters on non-string JSON members fail at apply (text > integer) #78

Closed

Description

@CaffeinatedCoder

Problem

A typed filter on an exclusion constraint that compares a non-string ToJson() member scaffolds SQL PostgreSQL rejects when the migration is applied:

b.HasExclusionConstraint(x => x.Count, x => x.Period, x => x.Doc.Rank > 5);   // Rank: int
// WHERE (("doc" ->> 'Rank') > 5)  →  42883 operator does not exist: text > integer

b.HasExclusionConstraint(ex => ex.WithEquality(x => x.Count).WithOverlaps(x => x.Period)
                                 .HasFilter(x => x.Doc.Active));               // Active: bool
// WHERE (("doc" ->> 'Active'))    →  42804 argument of WHERE must be type boolean, not type text

Both fail on PostgreSQL 16 and 18. docs/postgresql-constraints.md promises both JSON-member extraction and the typed-filter subset for exclusion filters.

Cause: BuildExclusionDescriptors resolves exclusion filters with renderingVersion: 1, which pins the pre-5.4.0 text-only JSON rendering so existing constraints never rebuild. The index path renders the same predicate as CAST(("doc" ->> 'Rank') AS integer) > 5 and applies.

Fix

Use the 5.4.0 rendering for non-string JSON leaves in exclusion filters. Under rendering 1 those filters never applied, so no existing constraint changes; string leaves keep rendering 1.

Loud (fails at apply), so it can ship in a patch. Found by the 5.5.0 pre-tag analysis (PostgreSQL satellite); present since 5.4.0.

Activity

  1. added this to the 5.5.1 milestone on Oct 19, 2026
  2. added
    bug
    severity/medium
    package/postgresql
    area/constraints
    on Oct 19, 2026
  3. modified the milestones: 5.5.1, 5.5.0 on Oct 20, 2026
  4. CaffeinatedCoder commented on Oct 20, 2026

    @CaffeinatedCoder
    OwnerAuthor

    Scope as built in #108: rather than every non-string leaf, the switch to the 5.4.0 rendering covers the leaves that rendering casts (numbers, booleans, uuid, enums). Primitive collections, json/jsonb, bytea and the date/time text fallbacks keep rendering 1, because the current rendering reads a primitive collection with -> (jsonb) where rendering 1 used ->> (text), and the two treat a JSON null differently, so {Doc.Tags} IS NOT NULL would have changed meaning. A cast keeps NULL as NULL. Also, "never applied" holds for comparisons and bare booleans; {Doc.Rank} IS NOT NULL did apply under rendering 1, but it holds for the same rows when cast, and both sides of the diff resolve alike, so it gets no migration.

  5. added a commit that references this issue on Oct 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/constraintsbugpackage/postgresqlseverity/medium

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions