简体   繁体   中英

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.

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.

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 命令结束(程序数据结束)时数据才可用,在这种特定情况下,程序从未终止,因为它旨在作为消费者工作。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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