【问题标题】:PSQL update query with json usuing shell script使用 shell 脚本的 PSQL 更新查询与 json
【发布时间】:2021-04-23 10:50:14
【问题描述】:

我想使用 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

【问题讨论】:

    标签: shell psql


    【解决方案1】:

    如果问题是“为什么运行此 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'"
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-01-18
      • 1970-01-01
      • 1970-01-01
      • 2018-01-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-12-22
      相关资源
      最近更新 更多