我正在努力用新行更新postgres表中的多维数组。在psql中:
CREATE TABLE list_of_arrays (my_array int[]);
INSERT INTO list_of_arrays VALUES ('{{1, 2}}');
UPDATE list_of_arrays SET my_array = my_array || '{{3, 4}}';
SELECT * FROM list_of_arrays;
产生数组:
{{1,2},{3,4}}
在psycopg2中,更新步骤失败:
row1 = [[1, 2]]
row2 = [[3, 4]]
cur.execute("INSERT INTO list_of_arrays VALUES (%s);", (row1,))
cur.execute("UPDATE TABLE list_of_arrays SET my_array = my_array || %s;",(row2,))
返回:
psycopg2.ProgrammingError: syntax error at or near "TABLE" LINE 1:
UPDATE TABLE list_of_arrays SET my_array = my_array || ARRAY
答案 0 :(得分:1)
我相信它应该是这样的:
cur.execute("UPDATE list_of_arrays SET my_array = my_array || %s;",(row2,))
没有关键字TABLE