pg.ddx.io pgsql-docs@postgresql.org mailing list archive
help / color / mirror / Atom feedREGEXP_REPLACE : How to use a column value in the regex
2+ messages / 2 participants
[nested] [flat]
* REGEXP_REPLACE : How to use a column value in the regex
@ 2020-02-17 06:37 PG Doc comments form <noreply@postgresql.org>
2020-03-18 02:39 ` Re: REGEXP_REPLACE : How to use a column value in the regex Bruce Momjian <bruce@momjian.us>
0 siblings, 1 reply; 2+ messages in thread
From: PG Doc comments form @ 2020-02-17 06:37 UTC (permalink / raw)
To: pgsql-docs@lists.postgresql.org; +Cc: abdulrahim.s@gmail.com
The following documentation comment has been logged on the website:
Page: https://www.postgresql.org/docs/12/functions-matching.html
Description:
The documentation doesn't talk about any regex syntax for using a column
from the db in the pattern. There is no mention if this is NOT supported.
All the examples are using static string and none using a DB column
values.
e.g. I have a field *portfolio* which had data like CloudPlatform (Public),
CloudPlatform (Private), MobilePlatfom (Public),.. etc
These values are coming from another table *platformtypes" which has these
values Public, Private, Hybrid...etc.
I want to replace these types from the portfolio names, i was able to do it
using string
*SELECT
Portfolios.PortfolioName,REGEXP_REPLACE(Portfolios.PortfolioName,'(\(Public\))',''),
but I would like to use something like
*REGEXP_REPLACE(Portfolios.PortfolioName,'(\(platformtypes.Name\)),'')*
^ permalink raw reply [nested|flat] 2+ messages in thread
* Re: REGEXP_REPLACE : How to use a column value in the regex
2020-02-17 06:37 REGEXP_REPLACE : How to use a column value in the regex PG Doc comments form <noreply@postgresql.org>
@ 2020-03-18 02:39 ` Bruce Momjian <bruce@momjian.us>
0 siblings, 0 replies; 2+ messages in thread
From: Bruce Momjian @ 2020-03-18 02:39 UTC (permalink / raw)
To: abdulrahim.s@gmail.com; pgsql-docs@lists.postgresql.org
On Mon, Feb 17, 2020 at 06:37:11AM +0000, PG Doc comments form wrote:
> The following documentation comment has been logged on the website:
>
> Page: https://www.postgresql.org/docs/12/functions-matching.html
> Description:
>
> The documentation doesn't talk about any regex syntax for using a column
> from the db in the pattern. There is no mention if this is NOT supported.
> All the examples are using static string and none using a DB column
> values.
> e.g. I have a field *portfolio* which had data like CloudPlatform (Public),
> CloudPlatform (Private), MobilePlatfom (Public),.. etc
> These values are coming from another table *platformtypes" which has these
> values Public, Private, Hybrid...etc.
> I want to replace these types from the portfolio names, i was able to do it
> using string
> *SELECT
> Portfolios.PortfolioName,REGEXP_REPLACE(Portfolios.PortfolioName,'(\(Public\))',''),
> but I would like to use something like
> *REGEXP_REPLACE(Portfolios.PortfolioName,'(\(platformtypes.Name\)),'')*
Sure, you can do it ('a' -> 'X'):
CREATE TABLE TEST (x text);
INSERT INTO test VALUES ('a');
SELECT REGEXP_REPLACE(relname, x, 'X') FROM pg_class, test;
regexp_replace
-----------------------------------------------
pg_toXst_36526
pg_toXst_36526_index
test
pg_stXtistic
pg_type
pg_toXst_2600
You can also combine column names with literal text ('ta' -> 'YY'):
SELECT REGEXP_REPLACE(relname, 't' || x, 'YY') FROM pg_class, test;
regexp_replace
-----------------------------------------------
pg_toast_36526
pg_toast_36526_index
test
pg_sYYtistic
I didn't think it was worth documenting this.
--
Bruce Momjian <bruce@momjian.us> https://momjian.us
EnterpriseDB https://enterprisedb.com
+ As you are, so once was I. As I am, so you will be. +
+ Ancient Roman grave inscription +
^ permalink raw reply [nested|flat] 2+ messages in thread
end of thread, other threads:[~2020-03-18 02:39 UTC | newest]
Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2020-02-17 06:37 REGEXP_REPLACE : How to use a column value in the regex PG Doc comments form <noreply@postgresql.org>
2020-03-18 02:39 ` Bruce Momjian <bruce@momjian.us>
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox