CREATE OR REPLACE FUNCTION some_find(db character varying, tablename character varying, what character varying)
RETURNS SETOF RECORD AS
$func$
DECLARE
where_query text;
temprow record;
BEGIN
where_query := '';
FOR temprow IN
SELECT "column_name" FROM INFORMATION_SCHEMA.COLUMNS
WHERE "table_catalog" = db
AND "table_name" = tablename
LOOP
where_query := where_query || ' OR "' || temprow."column_name" || '" LIKE ''%' || what || '%''';
END LOOP;
RETURN QUERY EXECUTE 'SELECT * FROM "' || tablename || '" WHERE false' || where_query;
END
$func$
LANGUAGE plpgsql;
SELECT * FROM some_find('somedb', 'sometable', 'sometext') AS t(field text); // Вот тут все равно придется указывать список полей.