Обсуждение: Match against a column of regexes?
Hi All,
I was wondering if there was an elegant way to match a given string against a column of regexes within PostgreSQL? I’m only working with a few tens of lines, so I can read them all into R and examine them 1-by-1, but I thought I would ask.
--Stephen
Stephen Froehlich
Sr. Strategist, CableLabs®
Tel: +1 (303) 661-3708
Stephen Froehlich <s.froehlich@cablelabs.com> writes: > I was wondering if there was an elegant way to match a given string against a column of regexes within PostgreSQL? I'monly working with a few tens of lines, so I can read them all into R and examine them 1-by-1, but I thought I would ask. Something like ... WHERE mystring ~ ANY (SELECT regex FROM regexes) should do. regards, tom lane
Actually, all I needed to do was to reverse the input text and the column name in the query: SELECT DISTINCT group_id FROM logins WHERE '[user_email]' ~* email_regex; --Stephen -----Original Message----- From: Tom Lane <tgl@sss.pgh.pa.us> Sent: Friday, October 18, 2019 1:27 AM To: Stephen Froehlich <s.froehlich@cablelabs.com> Cc: pgsql-novice@lists.postgresql.org Subject: Re: Match against a column of regexes? Stephen Froehlich <s.froehlich@cablelabs.com> writes: > I was wondering if there was an elegant way to match a given string against a column of regexes within PostgreSQL? I'monly working with a few tens of lines, so I can read them all into R and examine them 1-by-1, but I thought I would ask. Something like ... WHERE mystring ~ ANY (SELECT regex FROM regexes) should do. regards, tom lane