SQLAlchemy CoreのSQLステートメントを使用して、PostgreSQLテーブルの整数配列を更新しようとしています。最初にクエリジェネレータを使用してみましたが、その方法もわかりませんでした。私が使用している方言であるPsycopg2は、PostgreSQLが受け入れることができる形式に配列を自動的に形成できると思います。
テーブルスキーマは次のとおりです。
CREATE TABLE surveys (
survey_id serial PRIMARY KEY,
question_ids_ordered INTEGER[],
created_at TIMESTAMP NOT NULL DEFAULT now(),
);
そしてSQLAlchemyステートメント:
survey_id = 46
question_ids_ordered = [237, 238, 239, 240, 241, 242, 243]
with engine.begin() as conn:
conn.execute("""UPDATE surveys
SET question_ids_ordered = %s
WHERE survey_id = %s""",
question_ids_ordered, survey_id)
そして、私が受け取るトレースバックは次のとおりです。
Traceback (most recent call last):
File "foo.py", line 16, in <module>
res = add_question_to_group(current_user, 46, 358, question_ids_ordered, new_group_name="Jellyfish?")
File "/vagrant/workspace/panel/panel/survey.py", line 80, in add_question_to_group
question_ids_ordered, survey_id)
File "/home/vagrant/.virtualenvs/project/lib/python2.6/site-packages/sqlalchemy/engine/base.py", line 664, in execute
params)
File "/home/vagrant/.virtualenvs/project/lib/python2.6/site-packages/sqlalchemy/engine/base.py", line 808, in _execute_text
statement, parameters
File "/home/vagrant/.virtualenvs/project/lib/python2.6/site-packages/sqlalchemy/engine/base.py", line 831, in _execute_context
None, None)
File "/home/vagrant/.virtualenvs/project/lib/python2.6/site-packages/sqlalchemy/engine/base.py", line 827, in _execute_context
context = constructor(dialect, self, conn, *args)
File "/home/vagrant/.virtualenvs/project/lib/python2.6/site-packages/sqlalchemy/engine/default.py", line 513, in _init_statement
for p in parameters]
sqlalchemy.exc.StatementError: 'int' object is not iterable (original cause: TypeError: 'int' object is not iterable) 'UPDATE surveys\n SET question_ids_ordered = %s\n WHERE survey_id = %s' ([237, 238, 239, 240, 241, 242, 243], 46)
私は何が間違っているのですか?