1

I know how to do a distinct in SQLAlchemy, but I'm trying to take my existing SQLAlchemy distinct query and attach an additional static text column to the output to get the equivalent of

select 'extrainfo' as 'Extra_Info', user_id as 'User_Id' 
from (select distinct user_id from some_table) a;

I know how to do what is in the subquery. So far I have considered turning my original distinct query into a subquery then querying on that, but without luck thus far.

J. Doe
  • 23
  • 4
  • I don't know your API at all, but you don't need a subquery to do this in raw SQL, e.g. `select distinct 'extrainfo' as 'Extra_Info', user_id as 'User_id' from some_table;` – Tim Biegeleisen Nov 03 '17 at 01:56
  • oh wow that's embarrassing, I was trying `select 'extrainfo' distinct user_id from some_table`. I will work this back into sqlalchemy tomorrow and post back (if someone doesn't beat me) just for completeness, but this question is likely flawed. Thanks for the polite nudge in the right direction :) – J. Doe Nov 03 '17 at 02:45
  • Loosely related: https://stackoverflow.com/questions/7533146/how-do-i-select-literal-values-in-an-sqlalchemy-query – Ilja Everilä Nov 03 '17 at 07:09

0 Answers0