Skip site navigation (1) Skip section navigation (2)

Re: Difference in columns

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: (view raw, whole thread or download thread mbox)
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:
>> 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

In response to

pgsql-sql by date

Next:From: Craig RingerDate: 2008-05-11 19:58:56
Subject: Re: Difference in columns
Previous:From: Gurjeet SinghDate: 2008-05-11 18:36:12
Subject: Re: Difference in columns

Privacy Policy | About PostgreSQL
Copyright © 1996-2017 The PostgreSQL Global Development Group