Skip to content

Allow setting default schema #189

@rbroth

Description

@rbroth

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

with ORACLEDB.connect(password_variable='DB_PASSWORD') as conn:
    etl.execute("ALTER SESSION SET CURRENT_SCHEMA=dev_hr", conn)`

every 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.:

ORACLEDB = etl.DbParams(
    dbtype='ORACLE',
    host=os.getenv('DB_HOST'),
    port=1521,
    dbname=os.getenv('DB_NAME'),
    user='alice',
    current_schema='dev_hr'
)

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions