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
{{ message }}
Repository navigation
Allow writing parameters in text format (with a specific type OID) #4053
In some scenarios, it may be useful for people to write text encoding of data, where they provide the string directly (see #4046 (comment) for an example).
Consider doing together with #4052, which is the same for binary.
We still need to resolve the real type handler (so that we send the correct type OID if NpgsqlDbType/DataTypeName are specified)
But we need to bypass validation entirely, and also do special TextHandler writing (not the handler's). We could possibly add checks in NpgsqlParameter to go through UnknownTypeHandler's validation/length calculation/writing, but it's annoying to add special logic in this hot path for something that's a very exotic edge case.
Note that we already have the UnknownTypeHandler mechanis: if NpgsqlDbType is set to Unknown, Npgsql sends the user-provided string with type OID=0, and allows PG to infer the the type based on context. If the context is unambiguous (e.g. inserting into a table column), this should work just fine; the problem is only for ambiguous contexts.
@marco6 can you please comment on whether this could work for you? If so, then you don't need anything at all from us: just read out text values (even using the existing API in Npgsql 5.0), shove them in NpgsqlParameter.Value and set the NpgsqlDbType to Unknown.
changed the title [-]Allow writing parameters in text format[/-][+]Allow writing parameters in text format (with a specific type OID)[/+]on Oct 27, 2021
I have tested NpgsqlDbType.Unknown and it seems working in my current use-case as I am inserting into tables/using parameters in where clauses, so Postgres can actually infer the type itself. I will keep you updated if something strange comes out. Thank you for your support for now! 😄
Great - NpgsqlDbType.Unknown should indeed be a very reasonable solution for the majority of cases (especially those likely to be used with replication).
I've put this (and #4052) in the backlog to revisit in the future if necessary.
Activity
roji commentedon Oct 25, 2021
This is a bit less trivial than it looks:
Note that we already have the UnknownTypeHandler mechanis: if NpgsqlDbType is set to Unknown, Npgsql sends the user-provided string with type OID=0, and allows PG to infer the the type based on context. If the context is unambiguous (e.g. inserting into a table column), this should work just fine; the problem is only for ambiguous contexts.
@marco6 can you please comment on whether this could work for you? If so, then you don't need anything at all from us: just read out text values (even using the existing API in Npgsql 5.0), shove them in NpgsqlParameter.Value and set the NpgsqlDbType to Unknown.
[-]Allow writing parameters in text format[/-][+]Allow writing parameters in text format (with a specific type OID)[/+]marco6 commentedon Oct 30, 2021
I have tested
NpgsqlDbType.Unknownand it seems working in my current use-case as I am inserting into tables/using parameters in where clauses, so Postgres can actually infer the type itself. I will keep you updated if something strange comes out. Thank you for your support for now! 😄roji commentedon Oct 30, 2021
Great - NpgsqlDbType.Unknown should indeed be a very reasonable solution for the majority of cases (especially those likely to be used with replication).
I've put this (and #4052) in the backlog to revisit in the future if necessary.