bash - 将“tail -f”输出重定向到 COPY 命令
问题描述
我正在尝试将 tail -f -n 1 的输出重定向到 Postgres COPY 命令,要求是对 tail 命令的每个输出执行 COPY 命令。
出来了以下内容:
tail -f -n 1 <source_file> | xargs -n 1 psql -c 'copy <table_name> from stdin'
但这不起作用,因为 tail 命令的输出被用作 psql 命令的参数而不是标准输入。
还有更通用的:
tail -f -n 1 <source_file> | psql -tc "copy <table_name> from stdin"
不起作用,因为 COPY 命令在流的末尾而不是对每一行执行提交。
解决方案
意识到问题在于 COPY 不打算接受流,并且数据仅在 COPY 命令结束时才可用(程序中的数据结束),在这种特定情况下,程序从未终止,因为它打算作为消费者工作。
推荐阅读
- javascript - 有没有办法在 PHP 文件中隐藏 Javascript 代码?
- amazon-web-services - 如何将 Redrive 策略添加到具有加密 DLQ 的 SNS
- python - 如何按位置将变量插入字符串
- oracle - 如何在 PL SQL 中抛出异常?
- c# - 如何从浏览器获取 OAuth2 不记名令牌?
- java - 如何在android中添加截击
- c# - c#正则表达式过滤youtube视频的ID
- linux - 在运行时创建 SPIdev 设备
- jhipster - 当访问类型为 public 的客户端提供时,JWT 是否由 Keycloak 签名?
- php - 在 Laravel 请求中验证数组键