Re: PL/Java (was: stored procedures)

From: Joe Conway <mail(at)joeconway(dot)com>
To: Petre Scheie <petre(dot)scheie(at)nextelpartners(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: PL/Java (was: stored procedures)
Date: 2003-03-13 22:05:30
Message-ID: 3E7100AA.40308@joeconway.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

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

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2003-03-13 22:23:42 Re: timestamp 'default' question
Previous Message Dousak May (Phoebus Apollonus) 2003-03-13 21:51:23 Re: Function in selection?