Re: plpgsql question

Поиск
Список
Период
Сортировка
От Pandurangan R S
Тема Re: plpgsql question
Дата
Msg-id 5e744e3d0601042158v69269fb7r5a57fa114487ec19@mail.gmail.com
обсуждение исходный текст
Ответ на plpgsql question  (Matthew Peter <survivedsushi@yahoo.com>)
Ответы Re: plpgsql question  (Matthew Peter <survivedsushi@yahoo.com>)
Список pgsql-general
Assuming records is the name of a table...

create or replace function getrecord(int,text) RETURNS SETOF records as $$
DECLARE
row records%rowtype;
BEGIN
FOR row IN  SELECT * FROM my_tbl
WHERE ...
LOOP
RETURN NEXT row;
END LOOP;

RETURN;

END;
$$ LANGUAGE plpgsql;

On 1/5/06, Matthew Peter <survivedsushi@yahoo.com> wrote:
> I'm trying to do a simple SELECT * in plpgsql that returns a set of records
> as a row w/ columns, not a row into a variable, w/ some conditionals.
>
>  The function below is semi-pseudo with what I'm trying to... If anyone
> could give me an example that works by returning it as a resultset
> maintaining the columns, that would be awesome and I could take it from
> there.
>
>  I've read the pl/pgsql section of the docs and the Douglas book but I'm
> still confused on this issue...
>
>  Thanks
>
>  create or replace function getrecord(int,text) RETURNS SETOF records as $$
>  DECLARE
>  -- event := rows to return from the table below
>
>  BEGIN
>  event := SELECT * FROM my_tbl
>  WHERE 1 = 1
>  and my_tbl_id IN (0$1) ||
>  ' IF $2 IS NOT NULL THEN' || and username = $2 || 'END IF;'
>  ; -- end sql statement
>
>  RETURN event;
>
>  END;
>  $$ LANGUAGE plpgsql;
>
>
>
>
>  ________________________________
>  Yahoo! DSL Something to write home about. Just $16.99/mo. or less
>
>

В списке pgsql-general по дате отправления:

Предыдущее
От: Benjamin Smith
Дата:
Сообщение: Putting restrictions on pg_dump?
Следующее
От: Tony Wasson
Дата:
Сообщение: Monitoring PostgreSQL connections using cricket and pg_stat_activity