<p>I'm using a kubernetes and want to filter only the <strong>sampledb</strong> on my postgreSQL.</p>
<p>I tried to use this command:</p>
<pre><code>kubectl exec podname-89tq4763k23-klp83 -- bash -c &quot;psql -U postgres --tuples-only -P format=unaligned -c &quot;SELECT datname FROM pg_database WHERE NOT datistemplate AND datname &lt;&gt; 'postgres'&quot;;&quot;
</code></pre>
<p>but it does not show any output from my terminal, my expectation is it should show <strong>sampledb</strong> as an output</p>
<p>Tried using this command to list all databasename and it is working.</p>
<pre><code>kubectl exec -it podname-89tq4763k23-klp83 -- psql -U postgres -c &quot;\l&quot;
</code></pre>
<p>my question is how can I filter only the <strong>sampledb</strong> name from the list of databases?</p>
<pre><code>                                                 List of databases
    Name     |  Owner   | Encoding |  Collate   |   Ctype    | ICU Locale | Locale Provider |   Access privileges
-------------+----------+----------+------------+------------+------------+-----------------+-----------------------
 sampledb    | postgres | UTF8     | en_US.utf8 | en_US.utf8 |            | libc            |
 postgres    | postgres | UTF8     | en_US.utf8 | en_US.utf8 |            | libc            |
 template0   | postgres | UTF8     | en_US.utf8 | en_US.utf8 |            | libc            | =c/postgres          +
             |          |          |            |            |            |                 | postgres=CTc/postgres
 template1   | postgres | UTF8     | en_US.utf8 | en_US.utf8 |            | libc            | =c/postgres          +
             |          |          |            |            |            |                 | postgres=CTc/postgres
(4 rows)
</code></pre>
<p>Note: I'm also planning to use this kubectl command if it works as a variable for my bash script.</p>

生きがい
<p>I think your command needs a quoting fix.</p>
<pre><code>kubectl exec podname-89tq4763k23-klp83 -- bash -c &quot;psql -U postgres --tuples-only -P format=unaligned -c &quot;SELECT datname FROM pg_database WHERE NOT datistemplate AND datname &lt;&gt; 'postgres'&quot;;&quot;
</code></pre>
<p>Try this:</p>
<pre><code>kubectl exec $POD -- bash -c &quot;psql -U postgres -t -A -c \&quot;SELECT datname FROM pg_database WHERE NOT datistemplate AND datname &lt;&gt; 'postgres'\&quot;&quot;
</code></pre>
