<p>I am trying to execute a query on postgres pod in k8s via bash script but cannot get results when i select a large number of columns. Here is my query:</p>
<pre><code>kubectl exec -it postgres-pod-dcd-wvd -- bash -c &quot;psql -U postgres -c \&quot;Select json_build_object('f_name',json_agg(f_name),'l_name',json_agg(l_name),'email',json_agg(email),'date_joined',json_agg(date_joined),'dep_name',json_agg(dep_name),'address',json_agg(address),'zip_code',json_agg(zip_code),'city',json_agg(city), 'country',json_agg(country)) from accounts WHERE last_name='ABC';\&quot;&quot;
</code></pre>
<p>When i reduce the number of columns to be selected in the query, i get the results but if I use all the column names, the query just hangs indefinitely. What could be wrong here?</p>
<p>Update:</p>
<p>I tried using the query as :</p>
<pre><code>kubectl exec -it postgres-pod-dcd-wvd -- bash -c &quot;psql -U postgres -c \&quot;Select last_name,first_name,...(other column names).. row_to_json(accounts) from register_account WHERE last_name='ABC';\&quot;&quot;
</code></pre>
<p>But this also hangs.</p>

devcloud
<blockquote>
<p>When i try from inside the pod, It works but i need to execute it via bash script</p>
</blockquote>
<p>Means it is almost certainly the results pagination; when you run <code>exec -t</code> it sets up a TTY in the Pod, just like you were connected interactively, so it is likely waiting for you to press space or &quot;n&quot; for the next page</p>
<p>You can disable the pagination with <code>env PAGER=cat psql -c &quot;select ...&quot;</code> or use the <a href="https://www.postgresql.org/docs/9.5/app-psql.html" rel="nofollow noreferrer"><code>--pset pager=off</code></a> as in <code>psql --pset pager=off -c &quot;Select ...&quot;</code></p>
<p>Also, there's no need to run <code>bash -c</code> unless your <code>.bashrc</code> is setting some variables or otherwise performing work in the Pod. Using <code>exec -- psql</code> should work just fine, all other things being equal. You <em>will</em> need to use the <code>env</code> command if you want to go with the <code>PAGER=cat</code> approach, because <code>$ ENV=var some_command</code> <em>is</em> shell syntax, and thus cannot be fed directly into <code>exec</code></p>
