public inbox for [email protected]
help / color / mirror / Atom feedFrom: Bernice Southey <[email protected]>
To: Rich Shepard <[email protected]>
Cc: [email protected]
Subject: Re: Selecting all variations of job title in a list
Date: Fri, 28 Nov 2025 12:20:37 +0000
Message-ID: <CAEDh4nwz7aZraJzy0NZC5+e4LH9MqfL7V0o+XF332dus-HFUSA@mail.gmail.com> (raw)
In-Reply-To: <[email protected]>
References: <[email protected]>
<[email protected]>
<[email protected]>
Rich Shepard <[email protected]> wrote:
> Learning postgres regexp is at the top of my list.
It's well worth knowing a few regex tricks and they're surprisingly
easy to remember. I find these the most useful for ad hoc queries.
'|' for or as mentioned
'()' if you want to check part of an expression eg '(abc|xyz)pqr'
'^' to restrict it to the beginning
'$' to restrict it to the end
Here's an example with your list.
with x(t) as (values ('Asst Gen Mgr.'), ('Env Mgr,'), ('Gen Mgr.'),
('Mgr,'),('Plant Mgr.'))
select * from x where t ~ '(Asst Gen |Gen |Env |Plant |)Mgr(.|,)'
Here's a slightly fancier nested one, just for illustration.
with x(t) as (values ('Asst Gen Mgr.'), ('Env Mgr,'), ('Gen Mgr.'),
('Mgr,'),('Plant Mgr.'))
select * from x where t ~ '^((Asst |)Gen |Env |Plant |)Mgr(.|,)$'
I use regex in my tests and it's practically instant on a few thousand rows.
Thanks, Bernice
view thread (3+ messages)
reply
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: [email protected]
Cc: [email protected], [email protected], [email protected]
Subject: Re: Selecting all variations of job title in a list
In-Reply-To: <CAEDh4nwz7aZraJzy0NZC5+e4LH9MqfL7V0o+XF332dus-HFUSA@mail.gmail.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox