0

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.

1 Answer 1

2
select([table.c.id, table.c.value, literal("1").label("new_column")])
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.