Qualifying table names with database names in sqlalchemy

后端 未结 2 816
别那么骄傲
别那么骄傲 2021-01-20 15:23

I\'m using sqlalchemy with elixir on multiple databases. Currently everything works well with multiple sessions -- one bind to a different database. However, there are cases

2条回答
  •  面向向阳花
    2021-01-20 16:03

    Hit a similar issue with Oracle as the DB. The schema name was different between the DB instances, so hopefully this is analogous to your situation.

    The method to resolve this was to initially fire a simple query to the DB to determine the owner of the schema objects:

    SELECT owner FROM ALL_OBJECTS WHERE object_name = :obj_name AND object_type = :obj_type
    

    Then use the resulting scalar as the value for the schema parameter on your reflected tables:

    mytable = Table(name='my_table_name',
                    metadata=my_bound_metadata,
                    autoload=True,
                    schema=schema_owner)
    

提交回复
热议问题