Re: optimize/cleanup SQL

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: optimize/cleanup SQL
Дата
Msg-id 17998.1243610659@sss.pgh.pa.us
обсуждение исходный текст
Ответ на optimize/cleanup SQL  (Brandon Metcalf <brandon@geronimoalloys.com>)
Список pgsql-general
Brandon Metcalf <brandon@geronimoalloys.com> writes:
> For some reason this doesn't give me satisfaction that it's written
> optimally, but I haven't found another way.

>   SELECT round(CAST ((EXTRACT(EPOCH FROM clockout)
>               -EXTRACT(EPOCH FROM clockin))/3600 AS NUMERIC),2) AS hours
>     FROM timeclock;

> The clockin and clockout columns are of type timestamp.

timestamp, or timestamptz?  extract(epoch from timestamptz) is really
quite a cheap operation; there's no need to worry about performance
in that case.  If what's bothering you is ugliness, encapsulate this
as an inlineable SQL function.

            regards, tom lane

В списке pgsql-general по дате отправления:

Предыдущее
От: Grzegorz Jaśkiewicz
Дата:
Сообщение: Re: Converting each item in array to a query result row
Следующее
От: Emi Lu
Дата:
Сообщение: Re: How can I look at a recursive table dependency tree?