Rückgabe mehrer Datensätze

Hallo Wissende,
ich muss eine mir völlig unbekannte und undokumentierte Datenbank analysieren.
Dafür habe ich mir (mit meinem sehr begrenzten Wissen) eine Funktion geschrieben, welche mir einen Text in allen Tabellen und Spalten sucht.

Die Funktion arbeitet in soweit zufriedenstellend, allerdings hätte ich als Ausgabe gern eine Tabellenstruktur:
,,
Im Moment bin ich nur in der Lage einen zusammengesetzten String zurückzugeben.
Hier mal die Function

CREATE OR REPLACE FUNCTION myfnc_searchinalltable(such character varying)
  RETURNS SETOF character AS
$BODY$
DECLARE sSQL         character varying;
DECLARE f integer;
declare v record; 

BEGIN
   FOR v IN SELECT data_type,t.table_name,column_name FROM information_schema.columns c 
                join(select table_name from information_schema.tables where table_schema='public' and table_type ='BASE TABLE') t 
                on c.table_name = t.table_name LOOP

	if  v.data_type like 'character%' then
		sSQL = 'select count(*) from ' || v.table_name || ' where ' || v.column_name || ' = ''' || such || '''';
		EXECUTE sSQL INTO f ;
		if f > 0 then
			RETURN next  v.table_name || ' ' || v.column_name || ': ' || f;
		end if;
	end if;
    END LOOP;
    
END;
$BODY$
  LANGUAGE plpgsql VOLATILE
  COST 100
  ROWS 1000;

Ich habe es schon mit setof record versucht, weiß aber nicht wie ich die Rückgaben setze.

Gruß Steffen

Du kannst Dir dazu einen eigenen Datentyp bauen, das kann ganz trivial eine Tabelle sein:

test=# create table my_return_table (id int, col1 text, col2 text);                                                                          
CREATE TABLE
test=*# create or replace function bla(c int) returns setof my_return_table as $$declare i int; begin i:=0; while i < c loop return next (i, 'spalte1 zeile ' || i::text, 'spalte 2 zeile ' || i::text); i:=i+1; end loop; end;$$language plpgsql;
CREATE FUNCTION
test=*# select * from bla(3);
 id |      col1       |       col2
----+-----------------+------------------
  0 | spalte1 zeile 0 | spalte 2 zeile 0
  1 | spalte1 zeile 1 | spalte 2 zeile 1
  2 | spalte1 zeile 2 | spalte 2 zeile 2
(3 rows)

Hallo,
vielen Dank für die schnelle Antwort.
Das klappt ja schon mal :-).
Aber geht das auch ohne eine zusätzliche Tabelle zu erzeugen?

Gruß Steffen

Alternativ kannst Du auch ein Tool verwenden, dass sowas schon eingebaut hat:

ja, via CREATE TYPE:

test=*# create type my_return_table as (id int, col1 text, col2 text);
CREATE TYPE
test=*# create or replace function bla(c int) returns setof my_return_table as $$declare i int; begin i:=0; while i < c loop return next (i, 'spalte1 zeile ' || i::text, 'spalte 2 zeile ' || i::text); i:=i+1; end loop; end;$$language plpgsql;
CREATE FUNCTION
test=*# select * from bla(3);
 id |      col1       |       col2
----+-----------------+------------------
  0 | spalte1 zeile 0 | spalte 2 zeile 0
  1 | spalte1 zeile 1 | spalte 2 zeile 1
  2 | spalte1 zeile 2 | spalte 2 zeile 2
(3 rows)

@castorp:
ja das war das Einzige was ich vorher zum Thema gefunden hatte.
Allerdings will und darf ich keine zusätzliche Software installieren.

@akretschmer:
Vielen Dank, so werde ich es machen.

Gruß Steffen