From: Richard Huxton <dev@archonet.com>
To: Patrice OLIVER <oliverp21@free.fr>
Cc: pgsql-sql@postgresql.org
Subject: Re: stored procedures and type of returned result.
Date: Tue, 24 Aug 2004 10:26:12 +0100
Message-ID: <412B09B4.1080407@archonet.com> (raw)
In-Reply-To: <412AFEBC.4060404@free.fr>
References: <412AFEBC.4060404@free.fr>
Patrice OLIVER wrote:
> Hello,
>
> I'm new in PostgreSQL. It's very cool.
Hello, and yes it is isn't it :-)
> I would like to know how to return a set of records from a stored
> procedure.
>
> For example, i would like to execute these sql command from a stored
> procedure :
>
> select t.typnum, t.typcom, t.typcateg, s.symurlgraph from structure.type t
> left join structure.symbole s
> on t.typcode = s.typcode;
Broadly speaking you'll want something like:
CREATE TYPE my_return_type AS (
a integer,
b text
);
CREATE FUNCTION my_function(integer) RETURNS SETOF my_return_type AS '
SELECT foo_a, foo_b FROM foo WHERE foo_c = $1;
' LANGUAGE SQL;
You don't need to define your own type if you want to return the same
columns as a table, you can use the table-name instead.
For more complex cases where you need procedural code, you probably want
to read Stephan Szabo's set-returning-functions article on techdocs.
http://techdocs.postgresql.org/guides/SetReturningFunctions
HTH
--
Richard Huxton
Archonet Ltd
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-sql@postgresql.org
Cc: dev@archonet.com, oliverp21@free.fr
Subject: Re: stored procedures and type of returned result.
In-Reply-To: <412B09B4.1080407@archonet.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox