Re: can a function take a column name or is there another solution

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Mark King <fires10(at)gmail(dot)com>
Cc: pgsql-novice(at)postgresql(dot)org
Subject: Re: can a function take a column name or is there another solution
Date: 2011-04-18 15:37:50
Message-ID: 22946.1303141070@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

Mark King <fires10(at)gmail(dot)com> writes:
> I have a table with sampledate, meter1, meter2...etc
> I am trying to develop a function or query

> where:

> select sampledate, (meter1 - (select meter1 where sampledate = sampledate +
> interval '1 days')) as consumption from mytable;

> Any ideas how to make this work?

I think what you're looking for is window functions, specifically the
LEAD/LAG functions. You need Postgres >= 8.4 for those though.

regards, tom lane

In response to

Responses

Browse pgsql-novice by date

  From Date Subject
Next Message Mark King 2011-04-18 15:43:42 Re: can a function take a column name or is there another solution
Previous Message Oliveiros d'Azevedo Cristina 2011-04-18 15:35:19 Re: can a function take a column name or is there another solution