Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/309.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用python将dataframe插入actian PSQL数据库表_Python_Pandas_Psql_Actian - Fatal编程技术网

使用python将dataframe插入actian PSQL数据库表

使用python将dataframe插入actian PSQL数据库表,python,pandas,psql,actian,Python,Pandas,Psql,Actian,我想将文件“save.csv”的数据导入actian PSQL数据库表“new_table”,但出现错误 ProgrammingError: ('42000', "[42000] [PSQL][ODBC Client Interface][LNA][PSQL][SQL Engine]Syntax Error: INSERT INTO 'new_table'<< ??? >> ('name','address','city') VALUES (%s,%s,%s) (0) (

我想将文件“save.csv”的数据导入actian PSQL数据库表“new_table”,但出现错误

ProgrammingError: ('42000', "[42000] [PSQL][ODBC Client Interface][LNA][PSQL][SQL Engine]Syntax Error: INSERT INTO 'new_table'<< ??? >> ('name','address','city') VALUES (%s,%s,%s) (0) (SQLPrepare)")

Pandas有一个内置函数,用于将Pandas数据帧清空到名为的sql数据库中。这可能就是你要找的。使用此方法,您不必一次手动插入一行,但可以一次插入整个数据帧

如果您想继续使用您的方法,问题可能是尚未在数据库中创建表“new_table”。因此,你首先需要这样的东西:

CREATE TABLE new_table 
( 
Name [nvarchar](100) NULL, 
Address [nvarchar](100) NULL, 
City [nvarchar](100) NULL
)
编辑: 您可以在数据库中已经存在的表上使用以下命令来执行以下操作:

df.to_sql(
        "new_table",
        schema="name_of_the_schema",
        con=c.session.connection(),
        if_exists="append", # <--- This will append an already existing table
        chunksize=10000,
        index=False,
    )
df.to\u sql(
“新表”,
schema=“schema的名称”,
con=c.session.connection(),

如果_exists=“append”,#我也尝试过同样的方法,在我创建表的情况下,我只想使用Actian PSQL将pandas dataframe中的每一行插入数据库,但表是在数据库中创建的
df.to_sql(
        "new_table",
        schema="name_of_the_schema",
        con=c.session.connection(),
        if_exists="append", # <--- This will append an already existing table
        chunksize=10000,
        index=False,
    )