Re: Difference in columns

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: Difference in columns
Дата
Msg-id 21842.1210532282@sss.pgh.pa.us
обсуждение исходный текст
Ответ на Re: Difference in columns  ("Gurjeet Singh" <singh.gurjeet@gmail.com>)
Список pgsql-sql
"Gurjeet Singh" <singh.gurjeet@gmail.com> writes:
> On Sun, May 11, 2008 at 11:47 PM, Craig Ringer <craig@postnewspapers.com.au>
>> If you cannot assume that, you can use a subquery with limit and order
>> by to obtain the next record:
>> 
>> SELECT
>> a.ts,
>> (SELECT b.size FROM x b WHERE b.ts > a.ts ORDER BY b.ts ASC LIMIT 1)
>> - a.size AS difference
>> FROM x a;
>> 
>> ... but that'll be really slow for any significant number of entries.

> not really... if you have an index on the TS column.

The OP said this was a view, so it may well not have any easy way to
provide such an index.
        regards, tom lane


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

Предыдущее
От: "Gurjeet Singh"
Дата:
Сообщение: Re: Difference in columns
Следующее
От: Craig Ringer
Дата:
Сообщение: Re: Difference in columns