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

From Joe Conway
Subject Re: Q: How do I return differnt rows depending on values
Date
Msg-id 405B40C9.1070607@joeconway.com
Whole thread Raw
In response to Q: How do I return differnt rows depending on values in a PL/pgSQL function?  (Max Ahston <max@ahston.se>)
Responses Re: Q: How do I return differnt rows depending on values
List pgsql-general
Max Ahston wrote:
> create or replace function get_dns(varchar(40), varchar(40)) returns
> setof holder as
> '
> declare
>     r holder%rowtype;
> begin
>     IF ($2 == "tigris") then
>        for r in select Attribute, op, value FROM radreply
>        WHERE username = $1 loop
>            return next r;
>        end loop;
>        return;
>     END IF;
> end
> '
> language 'plpgsql';
>
> Returns the following:
>
> ERROR:  column "tigris" does not exist
> CONTEXT:  PL/pgSQL function "get_dns2" line 4 at if

Couple problems that I can see. First, that test should be:
   IF $2 = ''tigris'' then
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.

HTH,

Joe

pgsql-general by date:

Previous
From: Max Ahston
Date:
Subject: Q: How do I return differnt rows depending on values in a PL/pgSQL function?
Next
From: Josué Maldonado
Date:
Subject: Generate char surrogate key