Can Postgres functions be used as stored procedures?

From: Tod Hagan <todh(at)netwavelink(dot)com>
To: pgsql-sql(at)postgresql(dot)org
Subject: Can Postgres functions be used as stored procedures?
Date: 1998-07-27 17:24:33
Message-ID: 35BCB7D1.A926B9C@netwavelink.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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(at)bondcliff(dot)com todh(at)netwavelink(dot)com

Browse pgsql-sql by date

  From Date Subject
Next Message James Olin Oden 1998-07-27 20:34:57 Sequences...
Previous Message Vadim Mikheev 1998-07-27 06:14:22 Re: [SQL] SubQueries in FROM statement