You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
changed the title [-]Consider changing record reading to return tuples instead of object arrays[/-][+]Support reading PG records as tuples[/+]on Oct 8, 2022
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[].
Activity
[-]Consider changing record reading to return tuples instead of object arrays[/-][+]Support reading PG records as tuples[/+]Support reading PG record as tuple
roji commentedon Oct 8, 2022
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).
This won't work, since dynamically constructing a ValueTuple (via reflection) requires an object[].
Support reading PG record as tuple (#4701)