0

I'm struggling to update multidimensional arrays in my postgres table with new rows. In 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;

yields the array:

{{1,2},{3,4}} 

In psycopg2, however the update step fails:

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,))

returns:

psycopg2.ProgrammingError: syntax error at or near "TABLE" LINE 1:
UPDATE TABLE list_of_arrays SET my_array = my_array || ARRAY

1 Answer 1

1

I believe it should be like this:

cur.execute("UPDATE list_of_arrays SET my_array = my_array || %s;",(row2,))

without a keyword TABLE

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.