SQLAlchemy Join on Temporary Literal Text Column

Viewed 237

I'm new to SQLAlchemy and having trouble figuring out how to get the type of result back that I want.

I have a list of values outside of SQL, e.g. ['A', 'B', 'C', 'D'] that I'm querying against. I want to display a result that includes all of those list values even if nothing is returned from the SQL query for certain values. So if SQL returns:

___________________________
A | 23423.32
---------------------------
D | 3523.0

I would want the result to look like:

___________________________
A | 23423.32
---------------------------
B | None
---------------------------
C | None
---------------------------
D | 3523.0

I've been trying to use something like this (although it hasn't been working):

subquery = select([list_vals]).as_scalar().subquery()
session.query(subquery.c.MY_COLUMN,query_results.MY_COLUMN).outerjoin(query_results, query_results.MY_COLUMN == subquery.c.MY_COLUMN)

to somehow create a literal column and join with the actual query results but have not been able to get it to work. It's an Oracle database if that is helpful.

0 Answers
Related