Can Postgres functions be used as stored procedures?

Поиск
Список
Период
Сортировка
От Tod Hagan
Тема Can Postgres functions be used as stored procedures?
Дата
Msg-id 35BCB7D1.A926B9C@netwavelink.com
обсуждение исходный текст
Список pgsql-sql
All the examples in the documentation of user-defined sql functions
return a single result. It is possible to use the 'setof' keyword to
define a function that (for example) executes a query and returns all
the records?

Below is an example of my attempt to make this work. While the function
returns the proper number of rows, it's returning a numeric value
instead of the record for each row. When 'select * from bar' is executed
directly from psql it returns the proper records from the table -- is
there any way I can encapsulate this behavior in a function?

    create function foo () returns setof bar
            as 'select * from bar'
            language 'sql';

    =>select foo() as foobar;
       foobar
    ---------
    135895376
    135895376
    135895376
    135895376
    135895376
    135895376
    135895376
    135895376
    135895376
    135895376
    135895376
    (11 rows)

--
Tod Hagan                                              On assignment at:
Bondcliff Internet Group                                   NetWave, Inc.
tod@bondcliff.com                                   todh@netwavelink.com

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

Предыдущее
От: Vadim Mikheev
Дата:
Сообщение: Re: [SQL] SubQueries in FROM statement
Следующее
От: James Olin Oden
Дата:
Сообщение: Sequences...