Re: Help trying to write my first plpgsql function...

From: Bjørn T Johansen <btj(at)havleik(dot)no>
To: depesz(at)gmail(dot)com
Cc: PostgreSQL General <pgsql-general(at)postgresql(dot)org>
Subject: Re: Help trying to write my first plpgsql function...
Date: 2005-09-21 06:47:02
Message-ID: 433101E6.6030309@havleik.no
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

I am not sure why I used subselect, I just saw an example and followed it..

But now it's working as it should... Thx for all the help! :)

BTJ

On 9/19/05, Bjørn T Johansen <btj ( at ) havleik ( dot ) no> wrote:

CREATE OR REPLACE FUNCTION trykkStatus (pressID INTEGER)
RETURNS SetOf trykkstatus_type AS '
DECLARE
orderID ordrenew.id%TYPE;
tmprec trykkstatus_type%ROWTYPE;
BEGIN
select id into orderID from ordrenew where now() between trykkstart and produsert and
presseid = pressID limit 1;
if not found then
return;
end if;
select into tmprec (select 1 as colid, ordrenew.id, trykkstart, produsert,
presseid, product.name from ordrenew left outer join product on ordrenew.productid =
product.id where produsert < (select trykkstart from ordrenew where id=orderID) and
presseid = pressID order by produsert desc limit 1);

why do you use subselect here?
just do:
select 1 as colid, ordenew.id..... into tmprec from ordrenew left ....;

return next tmprec;
END;

dont forget to add "return;" before END;

depesz

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Roman Neuhauser 2005-09-21 06:51:00 Re: More efficient INs when comparing two columns
Previous Message Matthew Peter 2005-09-21 06:46:20 array_dims array_lower/upper distance