'Add database link in query generated by sqlalchemy core

I am new to sqlalchemy. I am trying to generate query using sqlalchemy core

from sqlalchemy.dialects import oracle, mssql
from sqlalchemy.sql import column, table, select, literal_column

def genrate_query(db_type):
    cols = [literal_column('foo'), literal_column('bar')]
    qry = select([cols]).select_from(table('some_table'))
    if db_type == 'mssql':
        return qry.compile(dialect=mssql.dialect(), compile_kwargs={"literal_binds": True})
    return qry.compile(dialect=oracle.dialect(), compile_kwargs={"literal_binds": True})

This is giving me:

SELECT foo, bar FROM some_table

I am trying to achieve

SELECT foo, bar FROM some_table@dblink

for oracle.

Trying to generate dialect specific queries that is @dblink for oracle, host.dbname.schema.some_table for mssql, any idea how to achieve it?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source