alter session set current_schema not working globally

Viewed 331

I am changing the schema in the main function

db_dwh.cursor.execute("alter session set current_schema = SCHEMA_NAME")

But when I am passing this db_dwh object to a function and trying to execute a query on a table I am getting table not found error, for this again I have to set schema using:

db_dwh.cursor.execute("alter session set current_schema = SCHEMA_NAME")

Is there any way to set schema at only one place globally?


PS The job running in Hadoop environment.

1 Answers

I expect your function has a different connection - I hope you're using a connection pool.

The comment has one solution.

Here are some other tools that are available. They may be useful, depending on your (or other readers) application architecture:

    def init_session(connection, requested_tag):
        connection.current_schema = 'ALISON'

    # Create the pool with a session callback
    pool = cx_Oracle.SessionPool(user="whoever", password=userpwd, dsn="orclpdb1", session_callback=init_session)

    # Get a connection from the pool.  It will always have the current schema
    # set to ALISON
    connection = pool.acquire()

    . . .  # Use the connection
Related