3

I am currently joining two tables returning rows where a column is in a list:

a = Table('a', server_metadata, autoload=True)
b = Table('b', server_metadata, autoload=True)

tickers = ['1', '2']
res = b.join(a).select().where(asset.c.code.in_(tickers)).execute()

This returns the correct rows and all the columns from both a and b. How can I only return all the columns of table b?

1 Answer 1

2

select corresponds to the SELECT ... part of the SQL query, and defaults to *; to limit it to b.*, you can give it a list containing the table b; with this construct however you need to wrap the FROM part into select_from or otherwise SQLAlchemy will generate a subquery fragment. Thus:

res = select([b]).select_from(b.join(a).\
    where(asset.c.code.in_(tickers))).execute()
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.