korma / Korma

Tasty SQL for Clojure.
http://sqlkorma.com
1.48k stars 222 forks source link

Cant add date to postgres table with timestamp column #372

Closed LukeDefeo closed 7 years ago

LukeDefeo commented 7 years ago

Hi i have created the following table in postgres

create table test (date TIMESTAMP);

I can insert like this

insert into test (date) values('2016-12-26T22:21:51');

In korma i do the following:

(defentity test)

(sql-only(insert test
                 (values {:date "2016-12-26T22:28:51"})))

But it gives the error:

PSQLException ERROR: column "date" is of type timestamp without time zone but expression is of type character varying Hint: You will need to rewrite or cast the expression. Position: 37 org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse (QueryExecutorImpl.java:2157)

I am using the latest version of the postgres sql driver i could find

[org.postgresql/postgresql "9.4-1201-jdbc41"]

How do i get the library to accept my date

LukeDefeo commented 7 years ago

Dunno why but its working now

LukeDefeo commented 7 years ago

I have been at this too long, i forgot i temporalily changed the type on the table to VARCHAR so i could carry on. It definitly doesnt work when the colunn type is timestamp

ls4f commented 7 years ago

Korma doesn't really manipulate arguments unless you specify transform/prepare, meaning you are actually trying to pass string to the column. Fixing that with https://github.com/clj-time/clj-time should be fairly trivial.

LukeDefeo commented 7 years ago

Thanks, i was passing a clj-date object but didnt realise i had to require that extra namespace... RTFM

If anyone else is reading this and in a similar situation you need to require the [clj-time.jdbc] namespace and then it will work.