New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Can't manage to map the custom pguint type #5621
Comments
To handle custom types, you need to implement a type converter - which will handle encoding and decoding the PostgreSQL binary representation received over the network to .NET The alternative is to transfer the value as a string and parse it yourself. |
All I've found about Npgsql mapping are referenced to the Composite or Enum types ( I didn't find any public Npgsql interface which I can use to make own Type converter. Could you provide an example or a link to one (for a base type converter), or share any tips on implementing a type converter? |
Yeah, contrary to composite/enum types, supporting a new base type involves implementing a type converter. So we already have UInt32Converter internally, since various internal types are stored as uints (oid, xid...). This converter should probably work for this type as well - it's mostly a matter of wiring it up correctly; for that, you can take a look at how the NodaTime plugin adds a resolver factory, and follow that example to register UInt32Converter etc. |
Unfortunately this extension does not have binary support yet, it's tracked in petere/pguint#23. We can't easily add support for it in Npgsql when this is missing. @EvgkvOutlook any particular reason the builtin int2/4/8 types aren't enough? If you just want to prevent negative values you could decide to define some domain types for them as described in https://www.postgresql.org/docs/current/domains.html These will be automatically supported by Npgsql if the underlying type is. |
@NinoFloris @roji like @EvgkvOutlook, I am also interested in supporting So, DB size is in our focus, not "unsignedness". Could you share any ideas how to support these types in npgsql without petere/pguint#23 ? is it possible at all? I'm ready to provide PR for (or fork of) |
It won't really be possible no, we currently don't have support for creating arrays, ranges or multiranges over textual format types. Our infrastructural support for the text format in general is quite new, mostly unused, and still needs tweaks. Your best bet would be to get that PR merged. |
@roji Thank you! I'll try out on your tip. |
@EvgkvOutlook I'm not sure which tip you're referring to there - if it's the one about UInt32Converter, then as @NinoFloris wrote above, that works only once binary support is added to the uint4 type in the PostgreSQL extension. |
Any update @EvgkvOutlook? Do you consider the issue solved from the npgsql side of things? |
@NinoFloris I ask you to keep the issue open for now: we are conversating with the developer of the pguint extension to bring it to an official state. And I haven't finished some tests yet. |
Steps to reproduce
A simple function that reads a row from the plain table with custom field type:
The issue
The database uses a custom type provided by the
pguint
extension (https://github.com/petere/pguint).The specific field type is
uint4
.That thing registers a set of custom types.
Then we make a target table with the one of these types.
Root Exception:
Inner Exception:
pguint
is C-based extension and does not create any composite type.I also tried to use NpgsqlDataSourceBuilder, but that ends up the same way:
Have you any suggestions and/or hints?
I've started using PostgreSQL not so long ago. Maybe I'm missing some obvious things.
Further technical details
Npgsql version: 8.0.2
PostgreSQL version: 16
Operating system: Linux (Ubuntu)
Other details about my project setup:
.NET 7
The text was updated successfully, but these errors were encountered: