【问题标题】:How to make a query for two tables in two different servers (python)?如何在两个不同的服务器(python)中查询两个表?
【发布时间】:2019-02-22 20:14:14
【问题描述】:

我遇到了以下问题:

我在不同的表中有两个不同的服务器:Oracle 和表“A”和 PostgreSQL 和表“B”。

我正在尝试通过python编写一个程序,它将这两个表连接起来并将结果写入csv文件。

最好的方法是什么? (将表从一个数据库导入到另一个数据库?在数据库外进行 JOIN?)

很乐意为您提供帮助!

【问题讨论】:

    标签: python database oracle postgresql


    【解决方案1】:
    import cx_Oracle
    from sqlalchemy import create_engine
    import pandas as pd
    
    engineORACLE = create_engine('oracle://user:password@ip:1521/ORACLE_SERVIVE_NAME')
    enginePOSTGRE = create_engine('postgresql://user@lip:5432/mydb')
    
    df1 = pd.read_sql_query('select * from tableA', con=engineORACLE)    
    df2 = pd.read_sql_query('select * from TableB',con=enginePOSTGRE)
    
    dfcombined = df1.merge(df2, on='blabla', how='left') # for left outer join, you can also do, 'right', 'outer' or 'inner' (change 'blabla' with the key!)
    

    这样的?

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-08-08
      • 1970-01-01
      • 2011-07-05
      • 1970-01-01
      • 2011-04-19
      • 1970-01-01
      • 2016-04-12
      相关资源
      最近更新 更多