title: Trying to find the last character in a non-standard length string
body: <p>I'm a relatively new coder and I've been struggling with the following problem for a few days. I am trying to separate the characters after the last period in an email address so I can group results by them. To do this for the text after the @ symbol, I wrote the following code:</p>
  
  <pre><code>select lower(substring(email, position('@' in email))) as email
  </code></pre>
  
  <p>This code returns things like @gmail.com or @yahoo.com, which I can then group by in my longer query. However, I would also like to compare the .com results to the .net results. When I type a similar query:</p>
  
  <pre><code>select lower(substring(email, position('.' in email))) as email
  </code></pre>
  
  <p>it returns the first period in the email address. So my email would be returned as .lastname@gmail.com rather than .com. I've experimented with right( and left(, but these don't work with substring in Postgresql. Does anyone have any other suggestions? Thanks!</p>