Python,是否将jsonb作为参数传递给postgres函数?

2024-05-15 04:23:25 发布

您现在位置:Python中文网/ 问答频道 /正文

有一个函数advanced.func_insert,其中有一个jsonb类型的参数

我试图通过以下考试:

data = [[1, 'textData111'], [2, 'textData222'], [3, 'textData333']]
df = pd.DataFrame(data, columns = ['id', 'text_data'])
j = json.loads(df.to_json(orient='records'))
j = json.dumps(j)

cursor = connection.cursor(cursor_factory=RealDictCursor)
cursor.callproc('advanced.func_insert', [j,])

它只是打印j,出于某种原因什么都不做,有什么不对


Tags: 函数json类型dfdata参数jsonbcursor
1条回答
网友
1楼 · 发布于 2024-05-15 04:23:25

最后不得不写下以下几行:

cursor.close()
connection.commit()

该函数应该向现有表插入行并返回void

相关问题 更多 >

    热门问题