0
我无法让我的查询工作。我有一个包含超过80k行数据的JSON文件。因为我一直有这么多问题,我切文档下降到三线只是为了看看我是否能在我之前尝试全80K线获得数据:使用Python和Psycopg2将JSON数据文件导入PostgreSQL
Import psycopg2
import io
readTest1 = io.open("C:\Users\Samuel\Dropbox\Work\Python and Postgres\test1.json", encoding = "utf-8")
readAll = readTest1.readlines()
我已经在网上看到,使用readlines方法是不最好的方法,但它是我知道的唯一方法。该方法读取文件中的三行。我不确定,但我预计这也会使它成为一个阵列。
conn = psycopg2.connect("dbname = python_trial user = postgres")
cur = conn.cursor()
cur.execute("CREATE TABLE test4 (data json);")
创建一个表只需要JSON数据:
cur.executemany("INSERT INTO test4 VALUES (%s)", readAll)
错误:
Traceback (most recent call last):
File "<pyshell#13>", line 1, in <module>
cur.executemany("INSERT INTO test4 VALUES (%s)", readAll)
TypeError: not all arguments converted during string formatting
我并不确切知道我在做什么错误。我也看到“\ n”当我打印(readAll)。我认为这是由使用readlines方法造成的,我不确定这是否也会搞乱我的查询。
检查出来的'json'库:HTTPS://docs.python。组织/ 3.4 /库/ json.html – Nicarus