1

In mysql, I could select custom none field from table static as this:

select brand, name, "10" as age from cars

How do I do the same for sqlAlchemy?

Thanks!

Ilja Everilä
  • 50,538
  • 7
  • 126
  • 127
Houy Narun
  • 1,557
  • 5
  • 37
  • 86
  • 2
    Possible duplicate of [How do I select literal values in an sqlalchemy query?](https://stackoverflow.com/questions/7533146/how-do-i-select-literal-values-in-an-sqlalchemy-query) – Ilja Everilä May 29 '18 at 14:14
  • Note that (generated) virtual columns have another meaning in MySQL: https://dev.mysql.com/doc/refman/5.7/en/create-table-generated-columns.html. – Ilja Everilä May 29 '18 at 14:23
  • I did try ‘literal_column()’ seem does not work for me, but ‘literal()’ is just working for this. Thanks for clarify that, @IljaEverilä – Houy Narun May 29 '18 at 14:29
  • with `literal_column('AmendID').label('AmendID')`, giving a result `ProgrammingError: (ProgrammingError) column "amendid" does not exist`. Actually, I made query of two tables, while those tables having the same columns, first table does not have column `AmendID`. I need to virtually created column `AmendID` for first table; so that I was able to union of both tables. this is i tried to get. – Houy Narun May 29 '18 at 14:38
  • try `literal('AmendID').label('AmendID')` – mad_ May 29 '18 at 15:37
  • You'll find clarification about `literal_column()` vs. `literal()` in the dupe target and its comments. Look for the paragraph starting with "Beware that the text argument is inserted into the query without any transformation". – Ilja Everilä May 29 '18 at 17:51

0 Answers0