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

Поиск
Список
Период
Сортировка
От Joe Conway
Тема Re: Q: How do I return differnt rows depending on values
Дата
Msg-id 405B40C9.1070607@joeconway.com
обсуждение исходный текст
Ответ на Q: How do I return differnt rows depending on values in a PL/pgSQL function?  (Max Ahston <max@ahston.se>)
Ответы Re: Q: How do I return differnt rows depending on values
Список 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 по дате отправления:

Предыдущее
От: Max Ahston
Дата:
Сообщение: Q: How do I return differnt rows depending on values in a PL/pgSQL function?
Следующее
От: Josué Maldonado
Дата:
Сообщение: Generate char surrogate key