I have an already existing oracle DB, and there are many tables. Each table has hundreds of the columns as such I don't want to define class. I use below code to create the table object and it seems works as I can print the columns:
def get_engine(username, password, db):
try:
connection = f"oracle+cx_oracle://{username}:{password}@{db}"
engine = sqlalchemy.create_engine(connection, arraysize=1000)
return engine
except SQLAlchemyError as e:
print(e)
engine = get_engine(username = username, password = password, db = db)
Base = declarative_base()
meta = Base.metadata
meta.bind = engine
schema = "beta"
activity = Table('ACTIVITY',
meta,
autoload=True,
autoload_with=engine,
schema=schema
)
stmt = select([
activity.columns.activity_date,
activity.columns.activity_number,
activity.columns.activity_user
]
).where(and_(
activity.columns.activity_date== date(2021, 9, 1)
# ,
# activity_date.columns.activity_user <> 'Mary George'
))
Then - I read the result into a pandas data frame
p = pd.DataFrame(results)
connection.close()
But i couldn't get the column names from the stmt, or the results.
Can you please shed some lights?
Thanks