From: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
---|---|
To: | "Gurjeet Singh" <singh(dot)gurjeet(at)gmail(dot)com> |
Cc: | "Craig Ringer" <craig(at)postnewspapers(dot)com(dot)au>, "Mag Gam" <magawake(at)gmail(dot)com>, pgsql-sql(at)postgresql(dot)org |
Subject: | Re: Difference in columns |
Date: | 2008-05-11 18:58:02 |
Message-ID: | 21842.1210532282@sss.pgh.pa.us |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-sql |
"Gurjeet Singh" <singh(dot)gurjeet(at)gmail(dot)com> writes:
> On Sun, May 11, 2008 at 11:47 PM, Craig Ringer <craig(at)postnewspapers(dot)com(dot)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
From | Date | Subject | |
---|---|---|---|
Next Message | Craig Ringer | 2008-05-11 19:58:56 | Re: Difference in columns |
Previous Message | Gurjeet Singh | 2008-05-11 18:36:12 | Re: Difference in columns |