1

我使用 sqlalchemy 引擎在 postgresql 表中插入数据。我不会在一行中插入列表,就好像列表是具有多个值的字符串一样。

query = text('INSERT INTO table (list_id, list_name) VALUES ({}, {}) RETURNING'.format(my_list,'list_name'))
result_id = self.engine.execute(query)

当我尝试执行我的代码时,我收到错误:

sqlalchemy.exc.ProgrammingError: (psycopg2.errors.SyntaxError) syntax error at or near "["
LINE 1: ...INTO table (list_id, list_name) VALUES (['str1...                                                             ^

[SQL: INSERT INTO table (list_id, list_name) VALUES (['str1', 'str1', 'str1'], 'list_name') RETURNING id]

我试图将我的列表表示为 str(my list) 但结果是相同的。我也尝试 str(['str1', 'str1', 'str1']).replace('[', '{').replace(']', '}')

我的表查询:

CREATE TABLE api_services (
                  id SERIAL PRIMARY KEY,
                  list_id VARCHAR,
                  list_name VARCHAR(255) NOT NULL
                  );
4

0 回答 0