Re: Is there a better way to do this? - Mailing list pgsql-general

From D. Dante Lorenso
Subject Re: Is there a better way to do this?
Date
Msg-id 46D4BCCA.4050307@lorenso.com
Whole thread Raw
In response to Re: Is there a better way to do this?  (Michael Glaesemann <grzm@seespotcode.net>)
List pgsql-general
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

pgsql-general by date:

Previous
From: Decibel!
Date:
Subject: Re: Geographic High-Availability/Replication
Next
From: Tom Lane
Date:
Subject: Re: Is there a better way to do this?