I created one function for create expression
def test(operator1, operation, operator2):
return literal_column(operator1).op(operation)(operator2)
Now when I call it with
test(1, '=', 1)
then it works
But when I pass
test('abc', '=', 'abc')
Then it gives error that abc is not a column.
开发者_高级运维I tried to convert it
def test(operator1, operation, operator2):
return literal_column(operator1, String).op(operation)(operator2)
But that was not working.
This will work if i call with
test("'abc'", '=', 'abc')
Is there any way, to get the type of operator1 and on that bases we can create literal_colum which will be map to same type of content ?
any literal value can be converted to an expression construct:
from sqlalchemy import literal_column, bindparam
# ? = ?, 1 will be bound
bindparam(1) == bindparam(1)
# " 1 = 1", literals rendered inline (no quoting is applied !!)
literal_column(str(1)) == literal_column(str(1))
精彩评论