Hi,
I have an situation where I have an interval of "zero" time that I would like to put with the other data in the table. When I try with the (simple-date:encode-interval :millisecond 0) I get the object
(simple-date:encode-interval :millisecond 0) #<SIMPLE-DATE:INTERVAL P>
But, when I try to insert this object into the table with the insert-dao, I get the following error (I have left out other fields, for other non-zero values of interval the insert works fine).
Database error 22007: invalid input syntax for type interval: "" Query: INSERT INTO mytable (someinterval) VALUES (interval E'') RETURNING somevalue [Condition of type CL-POSTGRES-ERROR:INVALID-DATETIME-FORMAT]
I'm using latest postmodern from the git repository https://github.com/marijnh/Postmodern.git
For now I'll use (simple-date:encode-interval :millisecond 1), but I'm wondering if this is an issue with postmodern or postgresql?
Hi,
Interesting. It seems to be happy if you give it a simple string "0 0:0:0", or, as you've uncovered, 1 millisecond. But it doesn't like the encoding if you use (simple-date:encode-interval :anything 0)
Sabra
2011/1/23 Slobodan Milnović slobodan.milnovic@gmail.com
Hi,
I have an situation where I have an interval of "zero" time that I would like to put with the other data in the table. When I try with the (simple-date:encode-interval :millisecond 0) I get the object
(simple-date:encode-interval :millisecond 0) #<SIMPLE-DATE:INTERVAL P>
But, when I try to insert this object into the table with the insert-dao, I get the following error (I have left out other fields, for other non-zero values of interval the insert works fine).
Database error 22007: invalid input syntax for type interval: "" Query: INSERT INTO mytable (someinterval) VALUES (interval E'') RETURNING somevalue [Condition of type CL-POSTGRES-ERROR:INVALID-DATETIME-FORMAT]
I'm using latest postmodern from the git repository https://github.com/marijnh/Postmodern.git
For now I'll use (simple-date:encode-interval :millisecond 1), but I'm wondering if this is an issue with postmodern or postgresql?
postmodern-devel mailing list postmodern-devel@common-lisp.net http://common-lisp.net/cgi-bin/mailman/listinfo/postmodern-devel
Hi Slobodan,
I've pushed a patch to fix this. You now get "0 milliseconds" when serializing an interval whose components are all 0. I hope that solves the problem.
Best, Marijn
On Mon, Jan 24, 2011 at 12:38, Marijn Haverbeke marijnh@gmail.com wrote:
Hi Slobodan,
I've pushed a patch to fix this. You now get "0 milliseconds" when serializing an interval whose components are all 0. I hope that solves the problem.
Best, Marijn
Hi Marijn,
In this case, the postgresql receives '0 milliseconds' which it doesn't like and reports an syntax error, but I have made a small change, that corrects this and outputs
interval '0 milliseconds'
which postgresql accepts happily. I hope I have managed to follow the spirit of the postmodern code and the algorythm around the part that I have changed.
Here is the diff, I hope this format is usefull for you, since this is the first time I have been using git diff. :-)
diff --git a/simple-date/cl-postgres-glue.lisp b/simple-date/cl-postgres-glue.lisp index c07e67b..d1de8e7 100644 --- a/simple-date/cl-postgres-glue.lisp +++ b/simple-date/cl-postgres-glue.lisp @@ -33,7 +33,7 @@ (defmethod cl-postgres:to-sql-string ((arg interval)) (multiple-value-bind (year month day hour min sec ms) (decode-interval arg) (if (= year month day hour min sec ms 0) - "0 milliseconds" + (values "0 milliseconds" "interval") (flet ((not-zero (x) (if (zerop x) nil x))) (values (format nil "~@[~d years ~]~@[~d months ~]~@[~d days ~]~@[~d hours ~]~@[~d minutes ~]~@[~d seconds ~]~@[~d milliseconds~]"
Hi Slobodan,
Ugh. That seems to always happen when I push something out without fully testing it. Thanks for the fix, applied.
Best, Marijn
On Tue, Jan 25, 2011 at 09:08, Marijn Haverbeke marijnh@gmail.com wrote:
Hi Slobodan,
Ugh. That seems to always happen when I push something out without fully testing it. Thanks for the fix, applied.
No problem, if you weren't making changes, I probably wouldn't know where exactly is the problem.
Thank you, and thanks for the great library that postmodern is! :-)
postmodern-devel@common-lisp.net