小编gil*_*sur的帖子

函数 crosstab(unknown,unknown) 不存在,但确实存在

我有一个交叉表函数,过去曾多次成功使用过,但现在它在最后转储所有数据,而不是将其转储到输出表中。似乎找不到交叉表。我对其进行了以下研究;

  • 如果 tablefunc 不存在则创建扩展;--- 答案是:扩展名“tablefunc”已经存在
  • 使用模式动物创建扩展 tablefunc;答案是:如上所述
  • 从 information_schema.routines 中选择 count(*),其中例程名称如“crosstab%”;----答案是6。

下面是一段函数代码: BEGIN str := '" " text,'; -- A1 单元格中的空白

FOR rec IN SELECT DISTINCT col_name FROM an_in_tbl ORDER BY col_name LOOP str := str || '"' || rec.col_name || '" 文本' ||','; 结束循环;

str:= substring(str, 0, length(str));

EXECUTE 'CREATE EXTENSION IF NOT EXISTS tablefunc;
DROP TABLE IF EXISTS an_out_tbl;
CREATE TABLE an_out_tbl AS
SELECT *
FROM crosstab(''select row_name, col_name, row_value from an_in_tbl order by 1'',   
             ''SELECT DISTINCT col_name …
Run Code Online (Sandbox Code Playgroud)

postgresql pivot crosstab

7
推荐指数
1
解决办法
1万
查看次数

标签 统计

crosstab ×1

pivot ×1

postgresql ×1