title: How to find the maximum length of data in a particular field in postgresql?
body: <p>I have a table "Users" and one of the column is "USERNAME". I am trying to find out the maximum length of the username by comparing all the usernames. I need this max value to use for another query. I tried </p>
  
  <pre><code>SELECT  max(length(users.username)),username 
  FROM users group by username; 
  </code></pre>
  
  <p>returns all the rows.</p>
  
  <p>Example:</p>
  
  <pre class="lang-none prettyprint-override"><code> USERNAME
  ----------
  Tara  
  Amyamyse  
  Tommy  
  John  
  </code></pre>
  
  <p>I would like to get the result as below:</p>
  
  <pre class="lang-none prettyprint-override"><code>MAX_Length     USERNAME
  --------------------
    8             Amyamyse
  </code></pre>