You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In oracle, when you write sql code targeting a db object without specifying it's schema, oracle assumes that is the same as the username e.g. if user alice connects to the db and executes SELECT * FROM mytable, oracle will interpret it as SELECT * FROM alice.mytable. If Alice wants her script to work with both dev_hr and prod_hr, she either has to prefix all of her object names with a variable (leading to clunky code), or run
withORACLEDB.connect(password_variable='DB_PASSWORD') asconn:
etl.execute("ALTER SESSION SET CURRENT_SCHEMA=dev_hr", conn)`
That would be a nice enhancement. I've have to do similar things in PostgreSQL before. We'd need to check the implementation for there, and what we need in SQLite (when you have multiple databases connected that act like schemas) and in MS SQL before we could add it.
In the meantime, the OracleDB docs suggest that the current_schema attribute is read/write, so it should be possible to shorten your code by:
In oracle, when you write sql code targeting a db object without specifying it's schema, oracle assumes that is the same as the username e.g. if user
alice
connects to the db and executesSELECT * FROM mytable
, oracle will interpret it asSELECT * FROM alice.mytable
. If Alice wants her script to work with bothdev_hr
andprod_hr
, she either has to prefix all of her object names with a variable (leading to clunky code), or runevery time she opens up a db connection.
It is possible to set the default schema for a session, so that you can specify what schema gets set before an unqualified db object name (see e.g. https://python-oracledb.readthedocs.io/en/latest/api_manual/connection.html#Connection.current_schema).
It would be useful if we added an attribute for DBParams that would allow setting the default schema, e.g.:
The text was updated successfully, but these errors were encountered: