Skip to content

Dynamic Schema selection on query #993

Answered by dantownsend
keinagae asked this question in Q&A
Discussion options

You must be logged in to vote

There's a few different options which should work.

Option 1 - extra_nodes

Define extra_nodes (see docs) on PostgresEngine:

DB = PostgresEngine({
    'database': 'my_database',
    'extra_nodes': {
        'schema_1': PostgresEngine({
            'database': 'my_database',
            'server_settings': {
                'search_path': 'schema_1',
            },
        }),
        'schema_2': PostgresEngine({
            'database': 'my_database',
            'server_settings': {
                'search_path': 'schema_2',
            },
        }),
    }
})

Then you can pass a node argument into each query:

await MyTable.select().run(node="schema_1")

Option 2 - define tables multiple times

Replies: 1 comment 6 replies

Comment options

You must be logged in to vote
6 replies
@dantownsend
Comment options

@keinagae
Comment options

@dantownsend
Comment options

@keinagae
Comment options

@dantownsend
Comment options

Answer selected by dantownsend
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants