交叉表问题 ("return and sql tuple descriptions are incompatible")

Crosstab Troubles ("return and sql tuple descriptions are incompatible")

我正在尝试计算 table 上的交叉表(恰好是一个简单的物化视图,但这应该无关紧要):

user=# select * from data;
 region |    date    | sum
--------+------------+-----
 East   | 2010-06-30 |  22
 East   | 2010-01-31 |  32
 East   | 2010-02-25 |  12
 North  | 2010-01-31 |  34
 North  | 2010-02-25 |  88
 South  | 2010-01-31 |  52
 South  | 2010-02-25 |  54
 South  | 2010-06-30 |  11
 West   | 2010-06-30 |  15
 West   | 2010-02-25 |  37
 West   | 2010-01-31 |  11
(11 rows)

当我尝试使用以下表达式计算数据的交叉表时,出现错误:

user=# SELECT * FROM
       crosstab('select region, date, sum from x order by 1') 
       AS ct (region text, d1 date, d2 date, d3 date);
ERROR:  return and sql tuple descriptions are incompatible

我不知道为什么会这样!这是源 table:

的架构
user=# \d data
 Materialized view "public.data"
 Column |  Type  | Modifiers 
 --------+--------+-----------
 region | text   | 
 date   | date   | 
 sum    | bigint | 

value 列的类型是 bigint,而不是 date:

SELECT * 
FROM crosstab(
    'select region, date, sum from data order by 1'
) 
AS result (region text, d1 bigint, d2 bigint, d3 bigint);

 region | d1 | d2 | d3 
--------+----+----+----
 East   | 22 | 32 | 12
 North  | 34 | 88 |   
 South  | 52 | 54 | 11
 West   | 15 | 37 | 11
(4 rows)