Я получаю странную ошибку при попытке сохранить запись с дат-временем в postgres. Иногда это работает, см. Первый пример. В других случаях это не работает.rails postgres date_time не работает должным образом
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 } %>
я нажимаю обновление PARAMS являются:
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, но он пытается установить час на 00 в sql, поэтому я не знаю, что с этим связано.
Вот моя схема:
# \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
рельсы v 4.1.8 Psql (9.3.2)
Я думаю, вам нужно сделать некоторые кастинга. См. Это сообщение и выполните поиск INTERVAL (re: timestamp без часового пояса). http://brendankemp.com/essays/dealing-with-time-zones-using-rails-and-postgres/ –