Funktion mit Parameterliste auf Tabelle anwenden

Nun möchte ich die folgende Funktion auf eine Tabelle anwenden.

 CREATE OR REPLACE FUNCTION tst (text) RETURNS record AS $$ DECLARE result record; BEGIN SELECT INTO result 5 AS id, $1 AS name, 'C'::char AS typ; return result; END; $$ LANGUAGE 'plpgsql';
CREATE TABLE tsttab( tsttext text );INSERT INTO tsttab (tsttext) VALUES ('TestText');

Ein

SELECT tst(tsttext) FROM tsttab;

erzeugt natürlich nur
tst

(5,TestText,C)

Aussehen soll es wieder so.

id | name | typ
----±---------±----
5 | TestText | C

Dank und Gruß - Ronny

CREATE FUNCTION foo(OUT a int, OUT b int, IN c int)
RETURNS record AS $$
BEGIN
a := c + 1; b := c + 2;
RETURN;
END;
$$ LANGUAGE plpgsql;

CREATE TABLE t(c int);
INSERT INTO t VALUES(10),(20);

postgres=# SELECT c, foo© FROM t;
c | foo
----±--------
10 | (11,12)
20 | (21,22)
(2 rows)

postgres=# SELECT c, (foo©).* FROM t;
c | a | b
----±—±---
10 | 11 | 12
20 | 21 | 22
(2 rows)


Von hier:

PostgreSQL SQL Tricks - PostgreSQL