PostgreSQL INSERT bigint []数组引用语法

时间:2014-12-10 14:27:49

标签: postgresql syntax

我需要使用数字数组UPDATE现有行。我目前仍然坚持关于引号的语法(我认为)。以下是我试过的查询......

测试1

WITH update_table_1 (id,column_b) AS 
(VALUES (1,'{22}'), (72,'{29, 5}')) 
UPDATE table_1 SET id = up.id, column_b = up.column_b FROM update_table_1 up 
WHERE up.id = table_1.id;

测试2

WITH update_table_1 (id,column_b) AS 
(VALUES (1,'{"22"}'), (72,'{"29","5"}')) 
UPDATE table_1 SET id = up.id, column_b = up.column_b FROM update_table_1 up 
WHERE up.id = table_1.id;

测试3

WITH update_table_1 (id,column_b) AS 
(VALUES (1,{22}), (72,{29, 5})) 
UPDATE table_1 SET id = up.id, column_b = up.column_b FROM update_table_1 up 
WHERE up.id = table_1.id;

测试4

WITH update_table_1 (id,column_b) AS 
(VALUES (1,{22}), (72,{"29","5"})) 
UPDATE table_1 SET id = up.id, column_b = up.column_b FROM update_table_1 up 
WHERE up.id = table_1.id;

1 个答案:

答案 0 :(得分:5)

您需要使用强制转换,数组[]构造函数或两者:

select '{1,2}'::bigint[];
select array[1,2];           -- this is an int[]
select array[1,2]::bigint[];

否则,Postgres会(正确地)抱怨未知的操作员类型等。