使用本地提供的列表从远程Postgresql数据库中删除记录

编程入门 行业动态 更新时间:2024-10-25 07:33:37
本文介绍了使用本地提供的列表从远程Postgresql数据库中删除记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

在工作的bash脚本中,我具有以下逻辑:

I have the following logic in a bash script that works:

#copy records to delete file to respective servers. faster than running locally scp -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null $dir/$server.records_to_delete.txt $server:/tmp/ # trigger the deletion on remote machine. deletion_status=$(psql -U test testdb -h $server -c "CREATE TEMP TABLE tmp_cdr (id int); COPY tmp_widgets FROM '/tmp/$server.records_to_delete.txt'; DELETE FROM widgets USING tmp_cdr WHERE widgets.id = tmp_widgets.id;")

但我试图将其合并为一个命令。因此,我不想将记录列表删除并删除到远程服务器,而是希望将其保留在本地,并以某种方式使用本地文件创建tmp_widgets。

But I'm trying to consolidate into one command. So instead of scp'ing the list of records to delete over to the remote server, I'd like to keep it local and just somehow create tmp_widgets using the local file.

任何建议将不胜感激

推荐答案

您无需将文件复制到服务器。您正在寻找的是 STDIN ,用于 COPY :

You don't need to copy the file to the server. What you're looking for is the STDIN for COPY:

cat records_to_delete.txt | psql $server -c "COPY tmp_widgets FROM STDIN;"

更多推荐

使用本地提供的列表从远程Postgresql数据库中删除记录

本文发布于:2023-10-19 14:56:42,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1507862.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:数据库中   列表   Postgresql

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!