fox*_*fox 4 postgresql psql command-line
我正在尝试在 bash 中编写一行快速代码,它将使用 psql 连接到数据库并删除两个表中的所有条目:
\connect some_db
DELETE from some_table
DELETE from another_table
Run Code Online (Sandbox Code Playgroud)
我想在一行 bash 脚本中执行此操作,如下所示:
psql -U <username> -c "\c some_db; DELETE from some_table; DELETE from another_table"
Run Code Online (Sandbox Code Playgroud)
但似乎我不能这样做,因为该\c
命令创建了一个新的上下文,后续命令不适用于该上下文。
从 CLI 中用一两行代码执行此操作的正确方法是什么?
小智 6
您不需要\c
在命令中指定-c
,您可以将数据库指定为参数psql
:
psql -U <username> -d some_db -c "DELETE from some_table; DELETE from another_table"
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
2882 次 |
最近记录: |