Postgresql SQLAlchemy:如何正确转义.update()的文本
在postgres+SQLAlchemy设置中使用JSONB列时,我们经常使用Postgresql SQLAlchemy:如何正确转义.update()的文本,postgresql,sqlalchemy,jsonb,Postgresql,Sqlalchemy,Jsonb,在postgres+SQLAlchemy设置中使用JSONB列时,我们经常使用.update()方法 例如: path = '{user,lastText}' text = 'Hello. Please activate folder \nD:\\foo\bar\some\more \t Thanks, yours "Ted"' db.session.query( Customer ).filter( Customer.custid == '10' ).update
.update()
方法
例如:
path = '{user,lastText}'
text = 'Hello. Please activate folder \nD:\\foo\bar\some\more \t Thanks, yours "Ted"'
db.session.query(
Customer
).filter(
Customer.custid == '10'
).update(
{Customer.context: func.jsonb_set(Customer.context, path, text)},
synchronize_session='fetch'
)
您可以看到文本中有大量有问题的字符,需要转义
推荐的方法是什么?
SQLAlchemy应该有这样一个模块?Ilja的答案是:
json.dumps()
这是一个很好的方法。使用
json.dumps()
。非常感谢。我把你的评论变成了答案。