无法在Postgres中使用交叉表 [英] Unable to use crosstab in Postgres

查看:256
本文介绍了无法在Postgres中使用交叉表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在OSX 10.9.2上的Postgres 9.2.1。

Postgres 9.2.1 on OSX 10.9.2.

如果我运行以下交叉表示例查询:

If I run the following crosstab example query:

CREATE EXTENSION tablefunc; 

CREATE TABLE ct(id SERIAL, rowid TEXT, attribute TEXT, value TEXT);
INSERT INTO ct(rowid, attribute, value) VALUES('test1','att1','val1');

SELECT *
FROM crosstab(
  'select rowid, attribute, value
   from ct
   where attribute = ''att2'' or attribute = ''att3''
   order by 1,2')
AS ct(row_name text, category_1 text, category_2 text, category_3 text);

我得到:错误:扩展名 tablefunc已经存在

但是如果我注释掉创建扩展

我得到:错误:函数交叉表(未知)不存在

如何退出这个恶性循环?

How can I get out of this vicious circle? Is it a known issue?

推荐答案

您可以将第一行更改为:

You can change the first line into:

CREATE EXTENSION IF NOT EXISTS tablefunc;

这篇关于无法在Postgres中使用交叉表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆