Reputation: 724
I'm trying to generate sqlalchemy code to match this SQL statement:
SELECT table.id, table.value, 1 as new_column FROM table;
I can get select([table.c.id, table.c.value, 1])
to work no problem, and it adds a new column to the results with the value of 1 as expected, but I have no control over the name of the column. I've tried to figure out a way to use label, but since the integer is not a sqlalchemy column, I can't use it.
Is there a way to get this the same behavior as the about raw sql in sqlalchemy?
In the worst case I can just use raw sql, but I would much prefer to use the sqlalchemy table object.
Upvotes: 0
Views: 668
Reputation: 76982
select([table.c.id, table.c.value, literal("1").label("new_column")])
Upvotes: 2