kaku21
kaku21

Reputation: 129

Python sqlalchemy how to deal with null

I made a flask webframe,and execute sql update on UI.now I meet a question an data value is json string content is :

{"username":"test","measureid":null}

When I use python sqlalchemy to update date:

sql="update dh_base_measure_get_10 set json="{\"username\":\"test\",\"measureid\":null}"
db.session.execute(sql)

but system get an error message:

StatementError: A value is required for bind parameter u'null' (original cause: InvalidRequestError: A value is required for bind parameter u'null')

it was caused by ["measureid":null] if ["measureid":""] it can be executed successfully,but [null] error.how to deal with the question???

Upvotes: 0

Views: 1877

Answers (1)

Sean Vieira
Sean Vieira

Reputation: 159905

SQLAlchemy's driver is mistaking :null as a named bind parameter instead of a value. Simply add a space after the colon to make it clear that null is a value:

sql = """update dh_base_measure_get_10
         set json='{"username": "test", "measureid": null}' """

Upvotes: 2

Related Questions