From: Joe Conway <mail@joeconway.com>
To: Petre Scheie <petre.scheie@nextelpartners.com>
Cc: pgsql-general@postgresql.org
Subject: Re: PL/Java (was: stored procedures)
Date: Thu, 13 Mar 2003 14:05:30 -0800
Message-ID: <3E7100AA.40308@joeconway.com> (raw)
In-Reply-To: <3E70FB3B.2050502@nextelpartners.com>
References: <3E70FB3B.2050502@nextelpartners.com>
Petre Scheie wrote:
> My DBA and I looked at the link on using SQL for stored procedures
> (thanks Neil!) and he raised a couple concerns:
>
> 1. In the example given, the query is directed at just one table; he
> says he needs to join multiple tables, and have it return a set. Can PG
> do this?
Pretty much any valid SQL statement will work. E.g.
CREATE TYPE ex1_tup AS (relname name, colname name);
CREATE OR REPLACE FUNCTION ex1(text) returns setof ex1_tup AS '
SELECT c.relname, a.attname
FROM pg_class c JOIN pg_attribute a ON a.attrelid = c.oid
WHERE relname = $1
' LANGUAGE 'sql';
regression=# SELECT * FROM ex1('pg_group');
relname | colname
----------+----------
pg_group | tableoid
pg_group | cmax
pg_group | xmax
pg_group | cmin
pg_group | xmin
pg_group | ctid
pg_group | groname
pg_group | grosysid
pg_group | grolist
(9 rows)
> 2. The docs say this ability to return a set is deprecated and may be
> removed in a future release. Why is that? Has this functionality been
> replaced by something else (better?)
That is referring to the older style of returning a set in the target
list. It would look like:
SELECT ex1('pg_group');
But that style has semantic problems, and in any case never really did
what you wanted (a single column could be returned, but a composite
return type just gave you back numeric pointers)
HTH,
Joe
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 from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-general@postgresql.org
Cc: mail@joeconway.com, petre.scheie@nextelpartners.com
Subject: Re: PL/Java (was: stored procedures)
In-Reply-To: <3E7100AA.40308@joeconway.com>
References: <3E70FB3B.2050502@nextelpartners.com> <3E7100AA.40308@joeconway.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