Received: from maia.hub.org (maia-2.hub.org [200.46.204.251]) by mail.postgresql.org (Postfix) with ESMTP id 624A9632889 for ; Sun, 25 Jul 2010 06:34:17 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.251]) (amavisd-maia, port 10024) with ESMTP id 92353-08 for ; Sun, 25 Jul 2010 09:34:09 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from smtp2.tech.numericable.fr (smtp2.tech.numericable.fr [82.216.111.38]) by mail.postgresql.org (Postfix) with ESMTP id 2D8836327BE for ; Sun, 25 Jul 2010 06:34:09 -0300 (ADT) Received: from [10.0.1.2] (abo-102-217-68.trs.modulonet.fr [85.68.217.102]) by smtp2.tech.numericable.fr (Postfix) with ESMTP id 9323218D806; Sun, 25 Jul 2010 11:34:07 +0200 (CEST) Cc: pgsql-docs@postgresql.org Message-Id: From: John Gage To: Peter Eisentraut In-Reply-To: <1280046663.28006.0.camel@vanquo.pezone.net> Content-Type: text/plain; charset=US-ASCII; format=flowed; delsp=yes Content-Transfer-Encoding: 7bit Mime-Version: 1.0 (Apple Message framework v936) Subject: Re: Another change to the same section once again to facilitate copying and pasting Date: Sun, 25 Jul 2010 11:34:07 +0200 References: <9A88E54D-2CF7-403F-A0D8-35B9ECDC7103@numericable.fr> <1279974089.22066.3.camel@vanquo.pezone.net> <1280046663.28006.0.camel@vanquo.pezone.net> X-Mailer: Apple Mail (2.936) X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.91 tagged_above=-5 required=5 tests=BAYES_00=-1.9, RCVD_IN_DNSWL_NONE=-0.0001, T_RP_MATCHES_RCVD=-0.01 X-Spam-Level: X-Archive-Number: 201007/153 X-Sequence-Number: 5809 In 34.4.3. SQL Functions with Output Parameters we have: CREATE FUNCTION sum_n_product (x int, y int, OUT sum int, OUT product int) AS 'SELECT $1 + $2, $1 * $2' LANGUAGE SQL; SELECT * FROM sum_n_product(11,42); sum | product -----+--------- 53 | 462 (1 row) Then in 34.4.7. SQL Functions Returning Sets we have (without an example SELECT statement): CREATE FUNCTION sum_n_product_with_tab (x int, OUT sum int, OUT product int) RETURNS SETOF record AS $$ SELECT $1 + tab.y, $1 * tab.y FROM tab; $$ LANGUAGE SQL; The problem is that if the reader copies and pastes the last function definition and then attempts to run it, quite obviously he gets an error because there is no table "tab". I would add a table definition and fill it with dummy data and then give two example SELECT statements after the function definition: CREATE TABLE tab ( y integer, z integer ); INSERT INTO tab VALUES (1, 2), (3,4), (5,6), (7,8); CREATE FUNCTION sum_n_product_with_tab (x int, OUT sum int, OUT product int) RETURNS SETOF record AS $$ SELECT $1 + tab.y, $1 * tab.y FROM tab; $$ LANGUAGE SQL; SELECT sum_n_product_with_tab(10); SELECT * from sum_n_product_with_tab(10); I think one of the things this presentation accomplishes is to emphasize that a table definition is really not much more than a type definition or object definition or what you will. That is not said derogatorily at all. Rather, I believe it emphasizes the extraordinary power of Postgresql. John