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ä
  • 45,748
  • 6
  • 100
  • 105
user1742188
  • 3,775
  • 6
  • 33
  • 57

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ä
  • 45,748
  • 6
  • 100
  • 105