Ho do I read a postgresql citext field with npgsql 3.0.0?

瘦欲@ 提交于 2020-01-03 04:42:08

问题


Say I have a table called "exampletable" in postgresql with a 100 citext typed fields, let's call them "field1", "field2" etc... How do I read these fields using npgsql? Ideally I would like to use the following sql:

select * from exampletable

But when I execute the sql using npgsql 3.0.0 I get the following NotSupportedException:

"The field field1 has a type currently unknown to Npgsql (OID 16466). You can retrieve it as a string by marking it as unknown, please see the FAQ..."

To overcome this I could manually cast all the fields to text in the sql query like so:

select field1::text, field2::text, ... field99::text, field100::text from exampletable

As you can see this is extremely verbose and cumbersome. Would I have to manually cast all fields to text in my query or is there some easier way to configure npgsql to allow citext types in the transfer? How would I handle other non-standard extension types in postgresql?

Any help will be appreciated.

Bonus question: I have tried finding the FAQ referenced in the exception message but I have failed to find anything. Do you know what page the message is referencing?


回答1:


Apologies, that type must have slipped through the cracks. I've opened an issue for it and will implement for 3.0.1.

In the meantime, you can either cast manually as you're down, or set your NpgsqlCommand's AllResultTypesAreUnknown to true. This will make Npgsql request all the resultset's columns in text, which you can then access. The FAQ is still in progress and not yet online, apologies for that as well.



来源:https://stackoverflow.com/questions/31921310/ho-do-i-read-a-postgresql-citext-field-with-npgsql-3-0-0

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!