DECLARE
alltables record;
table_all varchar;
BEGIN
for alltables in select distinct table_name , column_name
from information_schema.colunms
loop
table_all = alltables.table_name;
raise notice 'TAB_Name:% , table_all;
end loop;
return table_all;
在这里,我可以看到PgAdmin中(raise notice 'TAB_Name:% , table_all;
)消息选项卡中的所有表格
但是Data output tab (return table_all;)
只返回一列
如何在数据输出选项卡中显示所有表?
答案 0 :(得分:1)
我不确定,如果我理解您的查询。你可能不会写表函数。
CREATE OR REPLACE FUNCTION xxx
RETURNS TABLE(table_name text, column_name text)
AS $$
BEGIN
FOR table_name, column_name IN
SELECT c.table_name, c.column_name
FROM information_schema.columns
LOOP
RETURN NEXT;
END LOOP;
RETURN;
END;
$$ LANGUAGE plpgsql;
或稍微简单一点点
CREATE OR REPLACE FUNCTION xxx
RETURNS TABLE(table_name text, column_name text)
AS $$
BEGIN
RETURN QUERY
SELECT c.table_name, c.column_name
FROM information_schema.columns
RETURN;
END;
$$ LANGUAGE plpgsql;
你可以称之为
SELECT * FROM xxx();