From: | "D(dot) Dante Lorenso" <dante(at)lorenso(dot)com> |
---|---|
To: | Michael Glaesemann <grzm(at)seespotcode(dot)net> |
Cc: | Wei Weng <wweng(at)kencast(dot)com>, pgsql-general(at)postgresql(dot)org |
Subject: | Re: Is there a better way to do this? |
Date: | 2007-08-29 00:24:42 |
Message-ID: | 46D4BCCA.4050307@lorenso.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | 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
From | Date | Subject | |
---|---|---|---|
Next Message | Tom Lane | 2007-08-29 00:30:20 | Re: Is there a better way to do this? |
Previous Message | Decibel! | 2007-08-29 00:24:21 | Re: Geographic High-Availability/Replication |