I am getting a weird error when trying to save a record with a datetime to postgres. Sometimes it works, see the first example. Other times it doesn't work.
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"]]
works, no problems!
When I use a form with a
<%= f.datetime_select :conversation_time, { :start_year => 2010, :end_year => Date.today.year } %>
I click update, params are:
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 is:
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"]]
which causes this exception:
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.
Another weird thing is the hour in this case is 19 but it is trying to set the hour to 00 in the sql, so I dont know what is up with that either.
Here is my schema:
# \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.8 psql (9.3.2)