X-Original-To: pgsql-sql@postgresql.org Received: from poweredge.attiksystem.ch (adsl-soholight-4-c59-p029.vtx.ch [212.147.59.29]) by svr1.postgresql.org (Postfix) with ESMTP id 5B6F55E47C2 for ; Tue, 24 Aug 2004 06:56:26 -0300 (ADT) Subject: Re: stored procedures and type of returned result. MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Date: Tue, 24 Aug 2004 11:56:29 +0200 X-MimeOLE: Produced By Microsoft Exchange V6.0.6487.1 content-class: urn:content-classes:message Message-ID: <6C0CF58A187DA5479245E0830AF84F420803D5@poweredge.attiksystem.ch> X-MS-Has-Attach: X-MS-TNEF-Correlator: Thread-Topic: [SQL] stored procedures and type of returned result. Thread-Index: AcSJvJndzHN39CtgSXCuiQiNHYibtQAAwNpg From: "Philippe Lang" To: X-Archive-Number: 200408/252 X-Sequence-Number: 18749 Patrice, You might have a look at "views" as well. That's not strictily speaking a s= tored procedure, but maybe it's what you are searching for? Philippe Lang -----Message d'origine----- De : pgsql-sql-owner@postgresql.org [mailto:pgsql-sql-owner@postgresql.org]= De la part de Richard Huxton Envoy=E9 : mardi, 24. ao=FBt 2004 11:26 =C0 : Patrice OLIVER Cc : pgsql-sql@postgresql.org Objet : Re: [SQL] stored procedures and type of returned result. Patrice OLIVER wrote: > Hello, >=20 > 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=20 > procedure. >=20 > For example, i would like to execute these sql command from a stored=20 > procedure : >=20 > select t.typnum, t.typcom, t.typcateg, s.symurlgraph from structure.type t > left join structure.symbole s > on t.typcode =3D 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 =3D $1; ' LANGUAGE SQL; You don't need to define your own type if you want to return the same colum= ns 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 --=20 Richard Huxton Archonet Ltd ---------------------------(end of broadcast)--------------------------- TIP 3: if posting/reading through Usenet, please send an appropriate subscribe-nomail command to majordomo@postgresql.org so that your message can get through to the mailing list cleanly