Re: Q: How do I return differnt rows depending on values

From: Joe Conway <mail(at)joeconway(dot)com>
To: Max Ahston <max(at)ahston(dot)se>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Q: How do I return differnt rows depending on values
Date: 2004-03-19 18:49:45
Message-ID: 405B40C9.1070607@joeconway.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Joe Conway 2004-03-19 18:52:54 Re: another postgres article
Previous Message Max Ahston 2004-03-19 18:20:51 Q: How do I return differnt rows depending on values in a PL/pgSQL function?