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

From: Mark King <fires10(at)gmail(dot)com>
To: 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:43:42
Message-ID: BANLkTi=e6zTDbGzWyygiC_yUd+AH0G1fXA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

The Lead/Lag functions are exactly what I am looking for.
Thank you

On Mon, Apr 18, 2011 at 11:37 AM, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:

> 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

Browse pgsql-novice by date

  From Date Subject
Next Message H S 2011-04-18 18:42:19 "postgres" is needed by initdb but was not found
Previous Message Tom Lane 2011-04-18 15:37:50 Re: can a function take a column name or is there another solution