1
votes

I am trying to reflect an existing table from my database:

engine = sqlalchemy.create_engine("oracle://username:password@id", ...)
meta = sqlalchemy.MetaData()
myTable = sqlalchemy.Table("myTable", meta, autoload=True, autoload_with=engine,
                           oracle_resolve_synonyms=True)

That gave me an error:

AssertionError: There are multiple tables visible to the schema, you must specify owner

How do I specify the owner in sqlalchemy? The documentation does not mention anything about specifying owners. the table is actually a synonym so I have to use oracle_resolve_synonyms. I can technically execute raw queries but that is not something that I want to do.

2

2 Answers

4
votes

Here's the docs on MetaData: http://docs.sqlalchemy.org/en/latest/core/metadata.html#sqlalchemy.schema.MetaData

You probably want to instantiate MetaData with the schema owner:

meta = sqlalchemy.MetaData(engine, schema='ora_schema_owner')
1
votes

After reading through the source code, I found out that the owner can be specified through the schema keyword argument:

myTable = sqlalchemy.Table("myTable", meta, autoload=True, autoload_with=engine,
                           oracle_resolve_synonyms=True, schema="ownerName")