[postmodern-devel] Can interval be zero?

Slobodan Milnović slobodan.milnovic at gmail.com
Mon Jan 24 20:30:56 UTC 2011


On Mon, Jan 24, 2011 at 12:38, Marijn Haverbeke <marijnh at 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~]"




More information about the postmodern-devel mailing list