Function that creates a custom table AND returns it = impossible in pg?

Поиск
Список
Период
Сортировка
От Davor J.
Тема Function that creates a custom table AND returns it = impossible in pg?
Дата
Msg-id hl11bd$2fs3$1@news.hub.org
обсуждение исходный текст
Список pgsql-general
What I want is something similar to this:

CREATE OR REPLACE FUNCTION f( /* "some args..." */)
  RETURNS SETOF RECORD AS
$BODY$
DECLARE
 ...
BEGIN
 DROP TABLE IF EXISTS tbl_temp;

 CREATE TEMPORARY TABLE tbl_temp(
  -- "based on args..."
  );

 WHILE
  INSERT INTO tbl_temp VALUES (/*"some values"*/);
 END LOOP;

 /*create indexes on it, manipulate, whatever...*/

 RETURN QUERY SELECT * FROM tbl_temp;

END;
$BODY$
  LANGUAGE 'plpgsql'

The point is: only the function knows the structure (i.e. rowtype) of the
created table, not the initializer. The initializer is only supposed to
supply the arguments, run"SELECT * FROM f(some args);" and fetch the
results. Is this possible in Postgres??

(And for those who insist: no, the intializer can not run SELECT * FROM
f(some args) AS table("table structure...");" This would imply the
initializer already knows what the function will do. It goes beyond the
point of modularity: why not just skip the function then and let the
initializer write the whole query itself?)

Original post:
http://forums.devshed.com/postgresql-help-21/function-that-creates-a-custom-table-and-returns-it-impossible-675540.html

Kind regards,
Davor



В списке pgsql-general по дате отправления:

Предыдущее
От: "Davor J."
Дата:
Сообщение: Re: Function that creates a custom (temporary) table AND returns a pointer to it = impossible in pg?
Следующее
От: "Davor J."
Дата:
Сообщение: Function that creates a custom (temporary) table AND returns a pointer to it = impossible in pg?