gpt4 book ai didi

ruby-on-rails - rails postgres date_time 无法正常工作

转载 作者:行者123 更新时间:2023-11-29 12:20:23 26 4
gpt4 key购买 nike

尝试将带有日期时间的记录保存到 postgres 时出现奇怪的错误。有时它会起作用,请参见第一个示例。其他时候它不起作用。

UPDATE "client_comments" SET "comment" = $1, "conversation_time" = $2, "updated_at" = $3 WHERE "client_comments"."id" = 2  [["comment", "test2"], ["conversation_time", "2015-03-09 23:42:00.000000"], ["updated_at", "2015-03-16 23:50:32.307101"]]

工作,没问题!

当我使用带有

的表单时
<%= f.datetime_select :conversation_time, { :start_year => 2010, :end_year => Date.today.year } %>

我点击更新,参数是:

Parameters: {"utf8"=>"✓", "authenticity_token"=>"iz/MS9mI3K7H0dg05AFjaiKTudLpuG3ipAtApGbHEQA=", "client_comment"=>{"client_id"=>"1221", "user_id"=>"1", "company_id"=>"MON", "conversation_time(1i)"=>"2015", "conversation_time(2i)"=>"3", "conversation_time(3i)"=>"7", "conversation_time(4i)"=>"19", "conversation_time(5i)"=>"42", "comment"=>"test2"}, "commit"=>"Update Client comment", "id"=>"2"}

sql 是:

UPDATE "client_comments" SET "conversation_time" = $1, "updated_at" = $2 WHERE "client_comments"."id" = 2  [["conversation_time", "2015-03-08 00:42:00.000000"], ["updated_at", "2015-03-17 00:01:43.611166"]]

导致此异常的原因:

PG::DatatypeMismatch: ERROR:  column "conversation_time" is of type timestamp without time zone but expression is of type time without time zone at character 52
HINT: You will need to rewrite or cast the expression.

另一个奇怪的事情是,在这种情况下,小时是 19,但它试图在 sql 中将小时设置为 00,所以我也不知道这是怎么回事。

这是我的架构:

# \d+ client_comments
Table "public.client_comments"
Column | Type | Modifiers | Storage | Stats target | Description
-------------------+-----------------------------+------------------------------ --------------------------------+----------+--------------+-------------
id | integer | not null default nextval('client_comments_id_seq'::regclass) | plain | |
client_id | integer | | plain | |
user_id | integer | | plain | |
company_id | integer | | plain | |
comment | text | | extended | |
employee_user_id | integer | | plain | |
created_at | timestamp without time zone | | plain | |
updated_at | timestamp without time zone | | plain | |
conversation_time | timestamp without time zone | | plain | |
Indexes:
"client_comments_pkey" PRIMARY KEY, btree (id)
"index_client_comments_on_client_id" btree (client_id)
"index_client_comments_on_company_id" btree (company_id)
"index_client_comments_on_user_id" btree (user_id)
Has OIDs: no

rails v 4.1.8psql (9.3.2)

最佳答案

嗯,这不是一个完美的答案,但事实证明这是 rails 4.1 和 pg 0.17.1 或它们一起工作时的错误。我升级到 rails 4.2.1(刚出来)和 pg 0.18.1,一切终于好了。注意 pg 0.81.1 和更早版本的 rails 有一个 blob 支持的错误,但 4.2.1 似乎已经修复了这个问题。

关于ruby-on-rails - rails postgres date_time 无法正常工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29089235/

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