gpt4 book ai didi

c# - PostgreSQL:42883 运算符不存在:没有时区的时间戳 = 文本

转载 作者:行者123 更新时间:2023-11-29 11:28:48 25 4
gpt4 key购买 nike

我使用的是 Npgsql 3.0.3.0 和 PetaPoco 最新版本。

当我运行这个命令时:

var dateCreated = DateTime.Now; // just an example
var sql = new Sql("WHERE date_created = @0", dateCreated.ToString("yyyy-MM-dd HH:00:00"));
var category = db.SingleOrDefault<Category>(sql);

我收到以下错误:

Npgsql.NpgsqlException 42883: operator does not exist: timestamp without time zone = text

我理解错误消息是说我正在尝试将时间戳(日期)与文本进行比较,但是对我来说比较它们是完全有效的,因为我期望以下 SQL 语句 build :

SELECT * FROM category WHERE date_created = '2017-02-03 15:00:00'

出于性能原因,我真的不想将我的数据库列强制转换为文本。

最佳答案

您需要将值转换为 timestsamp:

var sql = new Sql("WHERE date_created = @0::timestamp", dateCreated.ToString("yyyy-MM-dd HH:00:00"));

关于c# - PostgreSQL:42883 运算符不存在:没有时区的时间戳 = 文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42033881/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com