From: | "Philippe Lang" <philippe(dot)lang(at)attiksystem(dot)ch> |
---|---|
To: | <pgsql-sql(at)postgresql(dot)org> |
Subject: | Re: stored procedures and type of returned result. |
Date: | 2004-08-24 09:56:29 |
Message-ID: | 6C0CF58A187DA5479245E0830AF84F420803D5@poweredge.attiksystem.ch |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-sql |
Patrice,
You might have a look at "views" as well. That's not strictily speaking a stored procedure, but maybe it's what you are searching for?
Philippe Lang
-----Message d'origine-----
De : pgsql-sql-owner(at)postgresql(dot)org [mailto:pgsql-sql-owner(at)postgresql(dot)org] De la part de Richard Huxton
Envoyé : mardi, 24. août 2004 11:26
À : Patrice OLIVER
Cc : pgsql-sql(at)postgresql(dot)org
Objet : Re: [SQL] stored procedures and type of returned result.
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
---------------------------(end of broadcast)---------------------------
TIP 3: if posting/reading through Usenet, please send an appropriate
subscribe-nomail command to majordomo(at)postgresql(dot)org so that your
message can get through to the mailing list cleanly
From | Date | Subject | |
---|---|---|---|
Next Message | Richard Huxton | 2004-08-24 10:41:11 | Re: stored procedures and type of returned result. |
Previous Message | Richard Huxton | 2004-08-24 09:26:12 | Re: stored procedures and type of returned result. |