Re: Querying for strings that match after prefix

Поиск
Список
Период
Сортировка
Искать
От
Joseph Brenner
Тема
Re: Querying for strings that match after prefix
Дата
Msg-id
200606021943.k52JhI392764@mail0.rawbw.com
Ответ на
Список
Дерево обсуждения
Querying for strings that match after prefix "badlydrawnbhoy" <badlydrawnbhoy@gmail.com>
Re: Querying for strings that match after prefix Joachim Wieland <joe@mcknight.de>
Re: Querying for strings that match after prefix Joseph Brenner <doom@kzsu.stanford.edu>
Re: Querying for strings that match after prefix John Sidney-Woollett <johnsw@wardbrook.com>
Re: Querying for strings that match after prefix "badlydrawnbhoy" <badlydrawnbhoy@gmail.com>
Re: Querying for strings that match after prefix Roman Neuhauser <neuhauser@sigpipe.cz>
Re: Querying for strings that match after prefix John Sidney-Woollett <johnsw@wardbrook.com>
Re: Querying for strings that match after prefix brian ally <brian@zijn-digital.com>
Re: Querying for strings that match after prefix John Sidney-Woollett <johnsw@wardbrook.com>
Re: Querying for strings that match after prefix brian ally <brian@zijn-digital.com>

badlydrawnbhoy  wrote:

> I hope this is the right forum for this, but please correct me if
> somewhere else is more appropriate.
> 
> I need to locate all the entries in a table that match , but only after
> a number of characters have been ignored. I have a table of email
> addresses, and someone else has erroneously entered some addresses
> prefixed with 'mailto:', which I'd like to ignore.
> 
> An example would be: john.smith@smiths.com should match
> mailto:john.smith@smiths.com
> 
> I've tried the following
> 
> select address
> from people
> where address = (select replace(address, 'mailto:', '') from people);
> 
> which gives me the error
> 
> ERROR:  more than one row returned by a subquery used as an expression



There's no need to use a sub-select for this, this should do the job:

  SELECT REPLACE(address, 'mailto:', '') FROM people;


You also have some options for "fuzzy" matching in the WHERE clause, e.g.  

  SELECT address FROM people WHERE address LIKE '%doom@%' 

Will find all email addresses like "doom@...", whether or not there's a
'mailto:' prefix.  (% matches any character string). 


This will find all the records with the erroneous "mailto:" prefix:

  SELECT address FROM people WHERE address LIKE 'mailto:%' 

В списке pgsql-general по дате отправления
От: Joseph Brenner
Дата:
От: Joshua D. Drake
Дата:
FAQ