【发布时间】:2014-02-24 19:12:46
【问题描述】:
我有一个包含整数数组的 JSON 列。我正在尝试将其转换为 INTEGER[] 列,但遇到了转换错误。
这是我的最终修改版本:
ALTER TABLE namespace_list ALTER COLUMN namespace_ids TYPE INTEGER[] USING string_to_array(namespace_ids::integer[], ',');
但是,这会引发以下错误:
ERROR: cannot cast type json to integer[]
有什么想法可以解决这种转换吗?我已经尝试了几件事,但我最终遇到了同样的错误。好像去 json --> string --> --> array 不起作用。我有哪些选择?
编辑:
表定义:
db => \d+ namespace_list;
Column | Type | Table "kiwi.namespace_list" Modifiers|
---------------+----------+--------------------------------------+
id | integer | not null default nextval('namespace_list_id_seq'::regclass)
namespace_ids | json | not null default '[]'::json
样本数据:
id | namespace_ids |
-------------------+
1 | [1,2,3] |
【问题讨论】:
-
提供一个表定义和一些示例值是礼貌的做法..
-
@ErwinBrandstetter 表定义已添加;几乎描述的内容(JSON 列)和示例数据。
标签: sql arrays json postgresql