gpt4 book ai didi

批处理脚本中的 PostgreSQL 命令自动化

转载 作者:行者123 更新时间:2023-11-29 12:16:46 24 4
gpt4 key购买 nike

我需要通过批处理作业自动执行以下命令,有没有办法做到这一点。当前命令提示符在执行第一步后停止(psql -U nrgadmin -d enwdb)。在 enwdb 数据库中,我需要手动执行从开始到提交的步骤。任何帮助,将不胜感激。

psql -U nrgadmin -d enwdb;

begin;
alter schema asset_enw rename to asset_enw_backup;
alter schema asset_import rename to asset_enw;
alter table enw.geom rename to geom_backup;
alter table enw.geom_backup set schema asset_enw_backup;
alter table import.geom set schema enw;
commit;

最佳答案

将命令放在脚本文件中,并在运行时使用 psql-f 选项。

psql -U nrgadmin -d enwdb -f myscript.sql

或者,如果您在 Unix 环境中,您可以将其全部放在 shell 脚本中的此处文档中并运行 shell 脚本。

#!/bin/sh
psql -U nrgadmin -d enwdb <<EOF
BEGIN;
alter schema asset_enw rename to asset_enw_backup;
#other statements
#--
COMMIT;
EOF

关于批处理脚本中的 PostgreSQL 命令自动化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49707592/

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