user1609817 user1609817 - 6 months ago 9
SQL Question

Remove part of an email address

I have emails like

sales@joebloggs.com
.

I am looking to select out everything after the
@
and before the
.
.

Result should be
joebloggs
.

Answer

Simple regex pattern should do the job.

SELECT regexp_matches('sales@joebloggs.subdomain.com', '@([^.]+)\.');

SQL Fiddle

Edit: fixed to support subdomains. I assume you want to get the part before first dot.