0

I have an application that needs to interact with a database through use of good old fashioned models as well as generated sql.

Session = sessionmaker(bind=engine)()
cmd = """insert into "STO_BANK_CONTROL" ("isn","TRANS_REF_NO","weird") values (8078638,'#:0057/13           ','');"""
Session.execute(cmd);

This raises the exception:

StatementError: A value is required for bind parameter u'0057' (original cause: InvalidRequestError: A value is required for bind parameter u'0057') u'insert into "STO_BANK_CONTROL" ("isn","TRANS_REF_NO","weird") values (8078638,\'#%(0057)s/13           \',\'\');' [{}]

but if I copy cmd straight into the psql console it works just fine.

My question is:

Why is sqlalchemy breaking working code and how do I prevent this from happening?

1 Answer 1

3

The problem was the colon. That notation is used to specify bind parameters. To fix it:

cmd = cmd.replace(':','\\:')
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.