title: PostgreSQL: how do I format the output of a query to show 'million' instead of zeros?
body: <p>How do I format the output of a query to display a value in number of millions (i.e 'million' appended. e.g: 1 million instead of 1000000) using psql?</p>
  <p>Example:</p>
  <pre><code>SELECT city, population
  FROM cities
  WHERE state = 'California';
  </code></pre>
  <p>Actual Output:</p>
  <pre><code>     city      | population 
  ---------------+--------------------------
   Los Angeles   |                  3990456
   San Diego     |                  1425976
   San Jose      |                  1030119
  </code></pre>
  <p>Desired Output:</p>
  <pre><code>     city      | population 
  ---------------+--------------------------
   Los Angeles   |             3.99 million
   San Diego     |             1.43 million
   San Jose      |             1.03 million
  </code></pre>
  <p>All I could find on the topic is functions for data formatting for converting numbers/dates to strings and vice-versa: <a href="https://www.docs4dev.com/docs/en/postgre-sql/11.2/reference/functions-formatting.html" rel="nofollow noreferrer">https://www.docs4dev.com/docs/en/postgre-sql/11.2/reference/functions-formatting.html</a></p>
  <p>Also, the to_char function does not seem to perform this sort of formatting: <a href="https://www.postgresqltutorial.com/postgresql-to_char/" rel="nofollow noreferrer">https://www.postgresqltutorial.com/postgresql-to_char/</a></p>
  <p>Using psql and PostgreSQL version 13 on macOS terminal.</p>