title: Specific psql query (ran from bash script) will get the terminal stuck
body: <p>I have this issue which is preventing me from concluding a bash script to automate some deployment routines. So inside my shellscript, I'm running a bunch of queries for which the responses are to remain at the screen (so the output may be manipulated/checked) until cancelled.</p>
  <p>Following function works like a charm when I call it from within an interactive area of my script. I can see the output on the screen and below it offers me to hit any key to proceed:</p>
  <pre><code>function function_1(){
  
     result=$(docker exec -it container psql -U postgres -c &quot;SELECT id FROM table WHERE state = 'initialized'&quot;)
     echo &quot;$result&quot;
     
     read -rsp $'PRESS &lt;ANY&gt; KEY TO CONTINUE...\n' -n1 key
     clear;
     &lt;back to the interactive screen&gt;
  }
  </code></pre>
  <p>However the following one (an exact copy of the previous function with a different SQL) will get stuck:</p>
  <pre><code>function function_2(){
     result2=$(docker exec -it container psql -U postgres -c &quot;SELECT id FROM table WHERE state IN('new', 'initializing', 'optimizing', 'finalizing')&quot;)   
     echo &quot;$result2&quot;
     read -rsp $'PRESS &lt;ANY&gt; KEY TO CONTINUE...\n' -n1 key
     clear;
     &lt;back to the interactive screen&gt;
  }
  </code></pre>
  <p><strong>By &quot;stuck&quot; I mean this:</strong></p>
  <p>The terminal will register the option that I took and will freeze indefinitely. When I press &quot;CTRL+C&quot;, it comes back and provides the expected output (however cropped in 2 lines).</p>
  <p>Finally, from within the postgres container, the following command works perfectly:</p>
  <pre><code>SELECT id 
  FROM table 
  WHERE state IN('new', 'initializing', 'optimizing', 'finalizing');
  </code></pre>
  <p>.
  .
  .
  <em><strong>UPDATE:</strong></em>
  .
  .
  .</p>
  <p>I was investigating whether the number of entries had anything to do wtih it. I've limited the output for 15 records and, for my surprise it worked fine. That is, the output did not get stuck and the queried information returned just fine.</p>
  <p>The hypothesis that the psql pager was the culprit rose to the top. I think I solved it using &quot;-P pager&quot; in the command. Example below:</p>
  <pre><code>result2=$(docker exec -it container psql -P pager -U postgres -c &quot;SELECT id FROM table WHERE state IN('new', 'initializing', 'optimizing', 'finalizing')&quot;)
  </code></pre>