Re: Is there a better way to do this?

Поиск
Список
Период
Сортировка
Искать
От
Michael Glaesemann
Тема
Re: Is there a better way to do this?
Дата
Msg-id
83132F43-384B-44EA-AE69-B872CF55EF70@seespotcode.net
Ответ на
Список
Дерево обсуждения
Is there a better way to do this? Wei Weng <wweng@kencast.com>
Re: Is there a better way to do this? Martijn van Oosterhout <kleptog@svana.org>
Re: Is there a better way to do this? David Fetter <david@fetter.org>
Re: Is there a better way to do this? "D. Dante Lorenso" <dante@lorenso.com>
Re: Is there a better way to do this? Michael Glaesemann <grzm@seespotcode.net>
Re: Is there a better way to do this? "D. Dante Lorenso" <dante@lorenso.com>
Re: Is there a better way to do this? Michael Glaesemann <grzm@seespotcode.net>
Re: Is there a better way to do this? Tom Lane <tgl@sss.pgh.pa.us>
Re: Is there a better way to do this? Ron Johnson <ron.l.johnson@cox.net>
Re: Is there a better way to do this? "D. Dante Lorenso" <dante@lorenso.com>
Re: Is there a better way to do this? Michael Glaesemann <grzm@seespotcode.net>
Re: Is there a better way to do this? Osvaldo Rosario Kussama <osvaldo_kussama@yahoo.com.br>
Re: Is there a better way to do this? "Rodrigo De León" <rdeleonp@gmail.com>
Re: Is there a better way to do this? Michael Glaesemann <grzm@seespotcode.net>
Re: Is there a better way to do this? Tom Lane <tgl@sss.pgh.pa.us>
Re: Is there a better way to do this? Michael Glaesemann <grzm@seespotcode.net>
Re: Is there a better way to do this? Michael Glaesemann <grzm@seespotcode.net>

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.

(days || ' days')::interval says "Make a string using this value (oh,  
it's an int? we need to cast it to text) and this string: the result  
just happens to match the proper input format for an interval, which  
is fortunate because now we're casting the string to interval". Okay,  
there's a little editorializing thrown in, but that's what the  
concatenation says to me.

The concatenation is probably less efficient: you're casting an int  
to text and then the text to interval with the concatenation you're  
using. I don't know how that compares in terms of cycles to the int *  
interval math, but efficiency isn't really the reason I would avoid it.

I'm sure others could provide more cogent explanations, but those are  
my initial thoughts.

Michael Glaesemann
grzm seespotcode net


В списке pgsql-general по дате отправления
От: Yonatan Ben-Nes
Дата:
Сообщение: Will Index improve the speed?
От: Ron Johnson
Дата:
FAQ