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

Re: PL/pgSQL function syntax question?

From: Lennin Caro <lennin(dot)caro(at)yahoo(dot)com>
To: pgsql-sql <pgsql-sql(at)postgresql(dot)org>, Ruben Gouveia <rubes7202(at)gmail(dot)com>
Subject: Re: PL/pgSQL function syntax question?
Date: 2008-09-09 14:36:44
Message-ID: 195942.79507.qm@web59513.mail.ac4.yahoo.com (view raw or flat)
Thread:
Lists: pgsql-sql


--- On Mon, 9/8/08, Ruben Gouveia <rubes7202(at)gmail(dot)com> wrote:

> From: Ruben Gouveia <rubes7202(at)gmail(dot)com>
> Subject: [SQL] PL/pgSQL function syntax question?
> To: "pgsql-sql" <pgsql-sql(at)postgresql(dot)org>
> Date: Monday, September 8, 2008, 9:40 PM
> i get the following error when i try and create the
> following function:
> 
> Basically, i am trying to have two different dates compared
> and only the
> most recent returned to me.  This seems pretty straight
> forward, what I am
> doing wrong here?
> 
> create or replace function fcn_pick_date(v_dt date)
> returns date as $$
>   DECLARE
>       v_dt date;
>   BEGIN
>     for v_record in select last_periodic, last_boot
>         from mediaportal
>     loop
>     if v_dt >= v_record.last_boot then
>        v_dt := v_record.last_periodic;
>     else
>         v_dt := v_record.last_boot;
>     end if;
>     end loop;
>     return (v_dt);
> END;
> $$ LANGUAGE 'plpgsql';
> 
> 
> ERROR:  loop variable of loop over rows must be record or
> row variable at or
> near "loop" at character 195
> 
> ********** Error **********
> 
> ERROR: loop variable of loop over rows must be record or
> row variable at or
> near "loop"
> SQL state: 42601
> Character: 195

where you declare v_record?

i think you have declare v_record to record or var array


      


In response to

pgsql-sql by date

Next:From: Ruben GouveiaDate: 2008-09-09 17:55:28
Subject: Function syntax ?
Previous:From: imadDate: 2008-09-08 23:28:51
Subject: Re: PL/pgSQL function syntax question?

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