Re: Difference in columns - Mailing list pgsql-sql

From Tom Lane
Subject Re: Difference in columns
Date
Msg-id 21842.1210532282@sss.pgh.pa.us
Whole thread Raw
In response to Re: Difference in columns  ("Gurjeet Singh" <singh.gurjeet@gmail.com>)
List 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 by date:

Previous
From: "Gurjeet Singh"
Date:
Subject: Re: Difference in columns
Next
From: Craig Ringer
Date:
Subject: Re: Difference in columns