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

时间:2019-04-10 07:48:14

标签: bash postgresql

我正在尝试将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命令的参数,而不是stdin。

也更通用:

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

不起作用,因为COPY命令在流的末尾而不是对每一行都执行提交。

1 个答案:

答案 0 :(得分:0)

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

相关问题