PostgreSQL将数组转换为二维

时间:2015-10-01 06:19:16

标签: sql arrays postgresql multidimensional-array casting

我是PostgreSQL的新用户,我在array中使用PostgreSQL类型

WITH intarr AS (
    SELECT
        ARRAY [ s.days,s.hours ] ::int[] AS arr
    FROM summary s
    WHERE s.hours != 2
)
SELECT ARRAY(SELECT * from intarr );

我收到此错误:

  

[Err]错误:找不到数据类型integer []

的数组类型

我找到了改变方式

ARRAY [ s.days,s.hours ] ::int[] AS arr 

到此

ARRAY [ s.days,s.hours ] ::varchar AS arr

我得到的结果如下:{"{1,3}","{2,3}"}。但我需要结果int[][]类型。我如何将one-dimensional array转换为two-dimensional array

1 个答案:

答案 0 :(得分:1)

我现在用它,我不认为它是完美的方式。

WITH intarr AS (
    SELECT
        ARRAY [ s.days,s.hours ] ::VARCHAR AS arr
    FROM
        summary s
    WHERE
        s.hours != 2
)
SELECT replace((SELECT ARRAY(SELECT arr from intarr)::VARCHAR), '"', '')::int[][]