Skip to content

Typed filters: a date or time JSON member compared with a column fails at apply (text against timestamp) #119

Closed

Description

@CaffeinatedCoder

Problem

A typed filter that compares a date or time member of a ToJson() document with a column scaffolds, then fails at apply:

b.HasComplexIndex(x => x.Id, x => x.Profile.At < x.ValidFrom, indexName: "ix_at");
CREATE INDEX "ix_at" ON accounts ("Id") WHERE ("profile" ->> 'At') < "ValidFrom";
-- ERROR: operator does not exist: text < timestamp with time zone

Since 5.4.0 a DateTime, DateTimeOffset, DateOnly or TimeOnly JSON member resolves to text, because the cast EF Core's queries use (CAST(... AS timestamp with time zone)) is not IMMUTABLE and cannot appear in an index. In a filter the text then meets a typed column. A comparison with a literal date is already refused at the declaration (dates have no portable literal), so only a comparison with another column or member reaches the database. Exclusion constraint filters, which keep the pre-5.4.0 rendering, fail the same way.

Fix

The translator cannot see that a path is a JSON member; the differ can. Refuse at migrations add a filter placeholder that resolves to a date or time JSON member's text fallback, naming the member and the string filter overload, the way ValidateQueryUsableLeadingParts refuses a non-unique index that starts with one. The place is the filter resolution (CustomMigrationsModelDiffer.ResolveFilter with NpgsqlComplexIndexMigrationsModelDiffer.ResolveUnmappedPart), outside the typed translator.

Loud. Found by the translator parity sweep (#101).

Activity

  1. added this to the 5.5.0 milestone on Oct 20, 2026
  2. added
    bug
    severity/low
    package/postgresql
    area/indexes
    area/constraints
    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/constraintsarea/indexesbugpackage/postgresqlseverity/low

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions