fukamachi / cl-dbi

Database independent interface for Common Lisp
206 stars 28 forks source link

Strange values for date type in postgres. #22

Closed aarvid closed 9 years ago

aarvid commented 9 years ago
CL-USER> (dbi:with-connection (conn :postgres
                           :database-name "dbtullius"
                           :username "utullius"
                           :password "********")
  (let* ((query (dbi:prepare conn
                             "SELECT current_date"))
         (result (dbi:execute query)))
    (dbi:fetch result)))
(:|date| 3650745600)
CL-USER> (local-time:unix-to-timestamp  (second *))
@2085-09-07T21:00:00.000000-03:00
CL-USER> (local-time:today)
@2015-09-08T20:00:00.000000-04:00
CL-USER> (local-time:timestamp-to-unix *)
1441756800

in psql:

dbtullius=> select current_date;
    date    
------------
 2015-09-09
(1 row)

I see the same thing when using real columns of the date type in real tables.

aarvid commented 9 years ago

I just tried postmodern and it gets the same results:

CL-USER> (postmodern:query "select current_date")
((3650745600))
1

So it is probably not a problem with cl-dbi. Will look into this some more.

fukamachi commented 9 years ago

Why don't you use universal-to-timestamp?

(local-time:universal-to-timestamp 3650745600)
;=> @2015-09-09T09:00:00.000000+09:00
aarvid commented 9 years ago

you are right. I noticed that these were seconds and assumed it was unix time. my bad. thanks for the response.