Michael Glaesemann wrote:
On Aug 28, 2007, at 17:22 , D. Dante Lorenso wrote:
Michael Glaesemann wrote:
On Aug 28, 2007, at 16:55 , D. Dante Lorenso wrote:
    RETURN time + (days || ' days')::INTERVAL;
It's bad practice to concatenate like this. Use time + days * interval '1 day' and be done with it.

Why? Is this functionality expected to break in the future or has unexpected side effects? Is it less clear or less efficient? Who declared it bad practice and where can I read that documentation?

It's generally bad practice to interpolate unnecessarily. You're right, in this case you're probably safe from this particular case ever changing. I personally find it less clear (though clarity is often in the eye of the beholder). time + * interval '1 day' is to me a clearer expression of what you're doing: add this multiple of days to the time.

Something in my just doesn't want to trust that:

        30 * interval '1 day' == interval '30 days'

Intervals are magical things unlike int and text. Doing multiplication on a magical thing is scary, but waiting until the end before applying the magic just *feels* safer.

I do like your syntax, though. There are less parentheses. Maybe I can warm up to it ;-)

-- Dante

---------------------------(end of broadcast)---------------------------
TIP 4: Have you searched our list archives?

              http://archives.postgresql.org/

Reply via email to