0

I want to create a scalar by concatenating multiple columns. If the list of columns were static I could do:

sa.select([table.c.col1 + table.c.col2 + 'done']).as_scalar()

But, my list is dynamic. Is there a way to do this without using eval()?

Ilja Everilä
  • 50,538
  • 7
  • 126
  • 127
user1742188
  • 4,563
  • 8
  • 35
  • 60

1 Answers1

1

You almost never need eval() — it can be evil. In this case just use functools.reduce() on your list of columns / expressions:

sa.select([reduce(operator.add, [table.c.col1, table.c.col2, 'done'])])
Ilja Everilä
  • 50,538
  • 7
  • 126
  • 127