簡體   English   中英

SQLAlchemy中的聯合聲明聲明

[英]Union statement statement in SQLAlchemy

我有多個大型 csv 文件,我想將它們合並並將最終表存儲在數據庫中,以便將來在 Pandas 中使用。 我使用 Pandas 閱讀了它們,並將它們作為單獨但相似的表存儲到 Sqlite 數據庫中。

我想通過 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)?

此外,我的代碼給了我一個錯誤,我不確定是否存在語法問題或我在這里遺漏的更重要的東西。

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)

這不是將查詢結果插入另一個表的正確語法。

它是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