Skip to content

Support reading PG records as tuples #4442

Description

@roji

npgsql/efcore.pg#2350 added row value support to the EF Core PG provider, using ValueTuple/Tuple to express a row value. This allows e.g. comparisons: (a, b) > (3, 4). However, we currently don't support projecting a row value out of the database (see this test for example).

In PG, row values are also known as records, or unnamed composite types. We already support reading them via Npgsql (but not writing them, as PG doesn't support that). However, we return an object array for records.

We could return a tuple instead. Aside from supporting the EF Core provider, It would probably be a more appropriate representation in any case.

Allowing the user to read a specific ValueTuple (e.g. reader.GetFieldValue<ValueTuple<int, int>>()) would also allow for reading without any heap allocation, which today's object array imposes.

There's still the question fo what we'd return by default - ValueTuple or Tuple.

Activity

  1. added this to the 7.0.0 milestone on May 7, 2022
  2. self-assigned this
    on May 8, 2022
  3. changed the title [-]Consider changing record reading to return tuples instead of object arrays[/-] [+]Support reading PG records as tuples[/+] on Oct 8, 2022
  4. added a commit that references this issue on Oct 8, 2022
    b94510a
  5. roji commented on Oct 8, 2022

    @roji
    MemberAuthor

    Making RecordHandler return a ValueTuple/Tuple isn't compatible with trimming (the tuple constructor wouldn't necessarily get preserved). So maybe it's better to keep object[] as the default (always works, also doesn't break backwards-compat), but add support for tuples optionally... Not changing the default for now (but am open to doing it too).

    Allowing the user to read a specific ValueTuple (e.g. reader.GetFieldValue<ValueTuple<int, int>>()) would also allow for reading without any heap allocation, which today's object array imposes.

    This won't work, since dynamically constructing a ValueTuple (via reflection) requires an object[].

  6. added a commit that references this issue on Oct 9, 2022
    49053b3
  7. added theissue type on Jun 18, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions