使用json的PSQL更新查询使用shell脚本



我想使用shell脚本运行以下内容。

psql -U postgres -d webstore -c "update business set subscription='{"nextSubscriptionPlan": null, "currentPlanEndDateTime": 1893456000000, "nextPlanSubscriptionId": null, "currentSubscriptionPlan": "Demo", "currentPlanSubscriptionId": null, "nextPlanActivationDateTime": null, "currentPlanActivatedDateTime": 1587050358298}' where businessid='buz_0000001'"

但我得到的回复低于预期。

FATAL:  invalid input syntax for type json
LINE 1: update business set subscription='{nextSubscriptionPl...
^
DETAIL:  Token "nextSubscriptionPlan" is invalid.
CONTEXT:  JSON data, line 1: {nextSubscriptionPlan...
server closed the connection unexpectedly
This probably means the server terminated abnormally
before or while processing the request.
connection to server was lost

如果问题是"为什么运行此SQL语句会导致错误&";,那么我相信你需要在你的终端命令中转义一些双引号:

psql -U postgres -d webstore -c "update business set subscription='{"nextSubscriptionPlan": null, "currentPlanEndDateTime": 1893456000000, "nextPlanSubscriptionId": null, "currentSubscriptionPlan": "Demo", "currentPlanSubscriptionId": null, "nextPlanActivationDateTime": null, "currentPlanActivatedDateTime": 1587050358298}' where businessid='buz_0000001'"

最新更新