首页 > 解决方案 > 如何将 colpivot 功能放在视图中?

问题描述

我正在使用函数 colpivot.sql ( https://github.com/hnsl/colpivot ) 将行动态转换为列。我需要将此查询的结果放在 PostgreSQL 的视图中。

CREATE OR REPLACE VIEW fun_test AS
    SELECT colpivot('_test_pivoted', 
            'select * from _test',
            array['year', 'month'], 
            array['country', 'state'], 
            '#.income', null);
    SELECT * FROM _test_pivoted;

当我执行查询时,它给了我以下错误:

ERROR: column "colpivot" has pseudotype void
SQL state: 42P16

我怎样才能让它工作?

标签: postgresqlfunctionview

解决方案


推荐阅读