简体   繁体   English

SQLAlchemy中的联合声明声明

[英]Union statement statement in SQLAlchemy

I have multiple large csv files that I want to merge and store the final table in a database for using in Pandas in the future.我有多个大型 csv 文件,我想将它们合并并将最终表存储在数据库中,以便将来在 Pandas 中使用。 I read them all using Pandas and store them as separate but similar tables into a Sqlite database.我使用 Pandas 阅读了它们,并将它们作为单独但相似的表存储到 Sqlite 数据库中。

I want to merge the rows (vertically) by a SQL string and then use them in pandas for more analyses.我想通过 SQL 字符串(垂直)合并行,然后在 pandas 中使用它们进行更多分析。 I was wondering if this is a good practice to go back and forth between pandas and SQL for when we deal with large files and have limited memory (16GB)? I was wondering if this is a good practice to go back and forth between pandas and SQL for when we deal with large files and have limited memory (16GB)?

Also my code gives me an error and I was unsure if there is a syntax issue or something more significant that I missing here.此外,我的代码给了我一个错误,我不确定是否存在语法问题或我在这里遗漏的更重要的东西。

from sqlalchemy.sql import text
engine = create_engine('sqlite:///C:\\master.db', echo=False)
string = text("""SELECT * INTO Flows FROM (select * from "f2007-08" UNION select * from "f2009-10")""")
engine.execute(string)

That's not the correct syntax for inserting the results of a query into another table.这不是将查询结果插入另一个表的正确语法。

It's INSERT INTO tablename SELECT...它是INSERT INTO tablename SELECT...

string = text("""
    INSERT INTO Flows 
    select * from "f2007-08" 
    UNION 
    select * from "f2009-10" 
""")

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM