0
CREATE FUNCTION cs_refresh_mviews() RETURNS integer AS $$
DECLARE
    mviews RECORD;
BEGIN
    PERFORM cs_log('Refreshing materialized views...');

    FOR mviews IN SELECT * FROM cs_materialized_views ORDER BY sort_key LOOP

       -- How For columns of mviews?

    END LOOP;

    PERFORM cs_log('Done refreshing materialized views.');
    RETURN 1;
END;
$$ LANGUAGE plpgsql;

我想获取 mviews 中列的值。mviews 的浏览器列如何用于 For 或 While?与以下相同:

For i=0 to mviews.columns.count step i++
    raise  mviews[i]
4

1 回答 1

0

物化视图,真的吗?你已经9.3了吗?
无论如何,您的问题不是很清楚,您是否尝试迭代每个视图中的所有列?

Information Schema 和information_schema.columns特别是您正在寻找的。

假设您在 cs_materialized_views 表中有一些schemaname字段,您可以执行以下操作:

声明另一个 Record 变量:mcols RECORD;

并将其放入您的循环中:

FOR mcols IN (SELECT ordinal_position, column_name FROM information_schema.columns WHERE table_schema = mviews.schema AND table_name = mviews.name ORDER BY ordinal_position) LOOP
    RAISE NOTICE 'View %, Column no. %: %', mviews.table_name, mcols.ordinal_position, mcols.column_name;
END LOOP;
于 2013-07-19T15:19:19.997 回答