gpt4 book ai didi

postgresql - 如何解决 postgres psql 命令中的这个问题?

转载 作者:行者123 更新时间:2023-11-29 14:13:32 26 4
gpt4 key购买 nike

在 psql shell 中。运行 sql 工作正常。但是当我使用 psql -c 时。它有问题。

postgres@03e0948a4fed:/home/data$ psql --c "select version();"
version
----------------------------------------------------------------------------------------------------------------------------------
PostgreSQL 11.4 (Debian 11.4-1.pgdg90+1) on x86_64-pc-linux-gnu, compiled by gcc (Debian 6.3.0-18+deb9u1) 6.3.0 20170516, 64-bit
(1 row)
postgres@03e0948a4fed:/home/data$ psql
psql (11.4 (Debian 11.4-1.pgdg90+1))
Type "help" for help.

postgres=# truncate table "TEST"."E0005";
TRUNCATE TABLE

postgres@03e0948a4fed:/home/data$ psql --c "truncate" "table" "TEST"."E0005";
psql: FATAL: role "TEST.E0005" does not exist

postgres@03e0948a4fed:/home/data$ psql --c "truncate table TEST.E0005;" `ERROR: schema "TEST" does not exist.`

最佳答案

有两个问题:

  1. -c 的参数不能是单个字符串
  2. 您不能在不转义的情况下嵌套相同的引号。

所以你有两个解决方案:

psql -c 'TRUNCATE TABLE "TEST"."E0005"'

psql -c "TRUNCATE TABLE \"TEST\".\"E0005\""

关于postgresql - 如何解决 postgres psql 命令中的这个问题?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57086148/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com