简体   繁体   English

将“tail -f”输出重定向到 COPY 命令

[英]Redirecting "tail -f" output to COPY command

I'm trying to redirect the output of the tail -f -n 1 to the Postgres COPY command, the requirement is to execute the COPY command for every output of the tail command.我正在尝试将 tail -f -n 1 的输出重定向到 Postgres COPY 命令,要求是为 tail 命令的每个输出执行 COPY 命令。

Came out with the following:出来了以下内容:

    tail -f -n 1 <source_file> | xargs -n 1 psql -c 'copy <table_name> from stdin'

but this is not working as the output of the tail command is used as a parameter for the psql command rather than as stdin.但这不起作用,因为 tail 命令的输出用作 psql 命令的参数而不是 stdin。

Also the more generic:还有更通用的:

    tail -f -n 1 <source_file> | psql -tc "copy <table_name> from stdin" 

is not working as the COPY command perform a commit at the end of the stream and not for every single row.无法正常工作,因为 COPY 命令在流的末尾而不是对每一行执行提交。

意识到问题在于 COPY 不打算接受流,并且仅当 COPY 命令结束(程序数据结束)时数据才可用,在这种特定情况下,程序从未终止,因为它旨在作为消费者工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM