Re: Q: How do I return differnt rows depending on values - Mailing list pgsql-general

From Max Ahston
Subject Re: Q: How do I return differnt rows depending on values
Date
Msg-id Pine.LNX.4.44.0403200834180.27242-100000@uplift.swm.pp.se
Whole thread Raw
In response to Re: Q: How do I return differnt rows depending on values  (Joe Conway <mail@joeconway.com>)
List pgsql-general
> Couple problems that I can see. First, that test should be:
>    IF $2 = ''tigris'' then
Thank you.

> Second, you'll need to add a "return;" line after the "END IF" for the
> cases where there is no match. In fact, you can just move the one from
> within the IF...END IF to outside it.
Ok, that explained an error I saw, but the function wasn't finished. This
is how the final result looks:

create or replace function get_dns2(varchar(40), varchar(40)) returns
setof holder as
'
declare
    r holder%rowtype;
begin
       IF ($2 = ''tigris'') then
          for r in select \'Acc-Dns-Server-Pri\', op, value FROM radreply
             where username = $1 and attribute =
\'Ascend-Client-Primary-DNS\' loop
             return next r;
          end loop;

          for r in select \'Acc-Dns-Server-Sec\', op, value FROM radreply
             where username = $1 and attribute =
\'Ascend-Client-Secondary-DNS\' loop
             return next r;
          end loop;
       ELSE
          for r in select Attribute, op, value FROM radreply
             WHERE username = $1 loop
             return next r;
          end loop;
       END IF;
       return;
end
'
language 'plpgsql';


Thanks for the help!

Max!


pgsql-general by date:

Previous
From: Steve Krall
Date:
Subject: Re: pg_dump on older version of postgres eating huge
Next
From: Martin Marques
Date:
Subject: Re: transactions in plpgsql