在psql外壳中。运行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.`

最佳答案

有两个问题:
brest的参数是一个字符串
不转义就不能嵌套相同的引号。
所以你有两个解决方案:

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


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

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

10-16 22:58