Can Postgres functions be used as stored procedures? - Mailing list pgsql-sql

From Tod Hagan
Subject Can Postgres functions be used as stored procedures?
Date
Msg-id 35BCB7D1.A926B9C@netwavelink.com
Whole thread Raw
List 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 by date:

Previous
From: Vadim Mikheev
Date:
Subject: Re: [SQL] SubQueries in FROM statement
Next
From: James Olin Oden
Date:
Subject: Sequences...