我有以下 python 脚本将数据插入 psql
from psycopg2 import connect
con = connect( """my string""")
query = """ INSERT INTO test.result_data
SELECT id,
result,
result1,
result2
FROM unnest(%s) s(id text, result real, result real, result integer)
"""
t = [('1234jc', 0.0, 1.2123, 1), ('1234sc', 1.0, 1.74, 1)]
c = con.cursor()
c.execute(query, (t,))
它抛出以下错误
psycopg2.ProgrammingError: function return row and query-specified return row do not match
DETAIL: Returned type unknown at ordinal position 1, but query expects text.
以下是数据库中的表结构
|---------------|-------|
|column name | type |
|---------------|-------|
|id | text |
|---------------|-------|
|result |float8 |
|---------------|-------|
| cpr |float8 |
|---------------|-------|
|cpr30 |float8 |
|---------------|-------|