Hi!
In order to convert timestamps from unix time to GMT strings I used the following select query: SELECT TIMESTAMP 'epoch' + 1195374767 * INTERVAL '1 second' or, the s-sql analogue `(:select (:+ (:type "epoch" timestamp) (:* ,unix-time (:type "1 second" interval)))) Surprisignly, it returned timestamps as numbers, not strings. After some investigation the reason of that behaviour became clear. Consider 2 following queries.
(pomo:query (:select 'timestamp :from 'sales :where (:and (:= 'vend-machine-id 2) (:< 'timestamp "2009-01-12")))) (("2009-01-11 18:37:18+03") ("2009-01-11 23:59:59+03") ("2009-01-11 23:59:59+03") ("2009-01-11 23:59:59+03") ("2009-01-11 23:59:59+03") ("2009-01-11 23:59:59+03"))
(pomo:query (:select (:type 'timestamp timestamp) :from 'sales :where (:and (:= 'vend-machine-id 2) (:< 'timestamp "2009-01-12")))) ((3440687838) (3440707199) (3440707199) (3440707199) (3440707199) (3440707199))
So, type-cast to TIMESTAMP makes postmodern to return timestamps as numbers. How is it possible to return unix-time as GMT strings via postmodern sql queries?
I think (remhash 1114 cl-postgres:*sql-readtable*) is what you want -- where 1114 is the OID of the timestamp type. Cl-postgres registers a binary interpreter for that type by default, since that makes it easier to stuff these values into custom datatypes (see set-sql-datetime-readers). Unregistering that interpreter-function will make it retrieve the values as strings.
Best, Marijn
Thanks, it works!
2009/2/2 Marijn Haverbeke marijnh@gmail.com:
I think (remhash 1114 cl-postgres:*sql-readtable*) is what you want -- where 1114 is the OID of the timestamp type. Cl-postgres registers a binary interpreter for that type by default, since that makes it easier to stuff these values into custom datatypes (see set-sql-datetime-readers). Unregistering that interpreter-function will make it retrieve the values as strings.
Best, Marijn
postmodern-devel mailing list postmodern-devel@common-lisp.net http://common-lisp.net/cgi-bin/mailman/listinfo/postmodern-devel
postmodern-devel@common-lisp.net