我如何使用npgsql 3.0.0读取Postgresql Citext字段?

编程入门 行业动态 更新时间:2024-10-24 01:59:16
本文介绍了我如何使用npgsql 3.0.0读取Postgresql Citext字段?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

假设我在postgresql中有一个名为 exampletable的表,其中包含100个citext类型的字段,我们将其称为 field1, field2等...如何使用npgsql读取这些字段?理想情况下,我想使用以下sql:

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

但是当我使用npgsql 3.0.0执行sql时,得到以下 NotSupportedException :

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

字段field1具有Npgsql当前未知的类型(OID 16466)。您可以通过将其标记为未知来将其检索为字符串,请参见常见问题...。

"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..."

要克服这一点,我可以将所有字段手动转换为sql查询中的文本,如下所示:

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

如您所见,这是非常冗长和繁琐的。我是否必须手动将所有字段都强制转换为查询中的文本,或者是否有一些更简单的方法来配置npgsql以允许在传输中使用citext类型?我将如何在Postgresql中处理其他非标准扩展类型?

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?

任何帮助将不胜感激。

奖金问题:我尝试查找异常消息中引用的FAQ,但未找到任何内容。您知道消息所引用的页面吗?

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?

推荐答案

抱歉,该类型一定已经漏过了。我为此打开了一个问题,并将在3.0.1中实现。

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

同时,您可以在倒下时手动进行强制转换,或将NpgsqlCommand的AllResultTypesAreUnknown设置为true。这将使Npgsql请求文本中所有结果集的列,然后可以访问它们。常见问题解答仍在进行中,尚未在线发布,为此深表歉意。

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.

更多推荐

我如何使用npgsql 3.0.0读取Postgresql Citext字段?

本文发布于:2023-10-23 02:13:09,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1519436.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:字段   如何使用   npgsql   Postgresql   Citext

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!