pg.ddx.io pgsql-docs@postgresql.org mailing list archive
help / color / mirror / Atom feedRe: Another change to the same section once again to facilitate copying and pasting
2+ messages / 2 participants
[nested] [flat]
* Re: Another change to the same section once again to facilitate copying and pasting
@ 2010-07-25 09:34 John Gage <jsmgage@numericable.fr>
0 siblings, 1 reply; 2+ messages in thread
From: John Gage @ 2010-07-25 09:34 UTC (permalink / raw)
To: Peter Eisentraut <peter_e@gmx.net>; +Cc: pgsql-docs
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
^ permalink raw reply [nested|flat] 2+ messages in thread
* Re: Another change to the same section once again to facilitate copying and pasting
@ 2010-07-26 20:15 Peter Eisentraut <peter_e@gmx.net>
parent: John Gage <jsmgage@numericable.fr>
0 siblings, 0 replies; 2+ messages in thread
From: Peter Eisentraut @ 2010-07-26 20:15 UTC (permalink / raw)
To: John Gage <jsmgage@numericable.fr>; +Cc: pgsql-docs
On sön, 2010-07-25 at 11:34 +0200, John Gage wrote:
> I would add a table definition and fill it with dummy data and then
> give two example SELECT statements after the function definition:
Done
^ permalink raw reply [nested|flat] 2+ messages in thread
end of thread, other threads:[~2010-07-26 20:15 UTC | newest]
Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2010-07-25 09:34 Re: Another change to the same section once again to facilitate copying and pasting John Gage <jsmgage@numericable.fr>
2010-07-26 20:15 ` Peter Eisentraut <peter_e@gmx.net>
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