Re: extracting the domain from an email address

From: Achilleas Mantzios <achill(at)matrix(dot)gatewaynet(dot)com>
To: pgsql-admin(at)lists(dot)postgresql(dot)org
Subject: Re: extracting the domain from an email address
Date: 2019-01-16 13:47:12
Message-ID: 0729dd40-9448-7529-155e-458676681b5e@matrix.gatewaynet.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-admin

On 16/1/19 3:20 μ.μ., Mark Steben wrote:
> Good morning,
> I am searching for a better more efficient way to extract the domain portion of an email address.  The two I have been using are very expensive.
>    The one extract I mostly use: substring(email from '@(.*)$')
>        also has an index on the email column which is the full email address:
> btree (email DESC) WHERE email::text = "substring"(email::text, '@(.*)$'::text) AND length(email::text) > 0,
>   The other extract:
> substr(e.email,(strpos(e.email, '@') + 1))
> Currently has no index.
Why don't you create an index on the extracted part including the where clause?
create index your_table_email_domain ON your_table(substring(email from '@(.*)$')) WHERElength(email::text) > 0 ;
>
> The referenced table has 72 million rows.  The email column can be empty (ergo the length = 0 check.  I am running postgresql 9.4.
>
> Any insights/observations welcome.
>
> --
> *Mark Steben*
>  Database Administrator
> @utoRevenue <http://www.autorevenue.com/> | Autobase <http://www.autobase.net/>
> CRM division of Dominion Dealer Solutions
> 95D Ashley Ave.
> West Springfield, MA 01089
> t: 413.327-3045
> f: 413.383-9567
>
> www.fb.com/DominionDealerSolutions <http://www.fb.com/DominionDealerSolutions>
> www.twitter.com/DominionDealer <http://www.twitter.com/DominionDealer>
> www.drivedominion.com <http://www.autorevenue.com/>
>
>
>
>
>

--
Achilleas Mantzios
IT DEV Lead
IT DEPT
Dynacom Tankers Mgmt

In response to

Browse pgsql-admin by date

  From Date Subject
Next Message Achilleas Mantzios 2019-01-16 15:24:40 pgBackRest : "ERROR: [042]: unexpected EOF reading line from remote process on" and stale pgbackrest processes hanging
Previous Message Mark Steben 2019-01-16 13:20:17 extracting the domain from an email address