Re: can a function take a column name or is there another solution - Mailing list pgsql-novice

From Tom Lane
Subject Re: can a function take a column name or is there another solution
Date
Msg-id 22946.1303141070@sss.pgh.pa.us
Whole thread Raw
In response to can a function take a column name or is there another solution  (Mark King <fires10@gmail.com>)
Responses Re: can a function take a column name or is there another solution
List pgsql-novice
Mark King <fires10@gmail.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

pgsql-novice by date:

Previous
From: "Oliveiros d'Azevedo Cristina"
Date:
Subject: Re: can a function take a column name or is there another solution
Next
From: Mark King
Date:
Subject: Re: can a function take a column name or is there another solution