Re: Help to realise function

From: Klint Gore <kg(at)kgb(dot)une(dot)edu(dot)au>
To: "Harvey, Allan AC" <HarveyA(at)OneSteel(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Help to realise function
Date: 2006-04-03 05:14:24
Message-ID: 4430AF30372.C322KG@129.180.47.120
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Mon, 3 Apr 2006 14:57:14 +1000, "Harvey, Allan AC" <HarveyA(at)OneSteel(dot)com> wrote:
> Hi all,
>
> Can anyone offer suggestions on how to realise this function....
>
> It is the $1 as the table name that is the problem.
>
> I'm using Version 7.4.5
>
> create or replace function last_scan( varchar, varchar ) returns float as '
> declare
> result float;
>
> begin
> result := value from $1 where parameter = $2 order by dt desc limit 1;
>
> return result;
> end;
> ' LANGUAGE plpgsql;

try executing the query

declare
r record;
begin
for r in execute 'select value from '||quote_ident($1)||' where
parameter = '||quote_literal($2)||' order by dt desc limit 1' loop
return r.value;
end loop;
return null;
end;

klint.

+---------------------------------------+-----------------+
: Klint Gore : "Non rhyming :
: EMail : kg(at)kgb(dot)une(dot)edu(dot)au : slang - the :
: Snail : A.B.R.I. : possibilities :
: Mail University of New England : are useless" :
: Armidale NSW 2351 Australia : L.J.J. :
: Fax : +61 2 6772 5376 : :
+---------------------------------------+-----------------+

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Tino Wildenhain 2006-04-03 07:58:07 Re: PostgreSQL's XML support comparison against other RDBMSes
Previous Message Harvey, Allan AC 2006-04-03 04:57:14 Help to realise function