Select columns by file containing primary keys
This assumes you are on a shell and have the tr command in the PATH:
psql -c &quot;SELECT * FROM mytable WHERE id IN (`tr '\n' , &lt;file`NULL)&quot;

Every newline character is replaced with ,, and the NULL in the end takes care of the final comma.