Re: Making substrings uppercase - Mailing list pgsql-general

From David Johnston
Subject Re: Making substrings uppercase
Date
Msg-id 1378734074389-5770108.post@n5.nabble.com
Whole thread Raw
In response to Making substrings uppercase  (Oliver Kohll - Mailing Lists <oliver.lists@gtwm.co.uk>)
Responses Re: Making substrings uppercase  (Oliver Kohll - Mailing Lists <oliver.lists@gtwm.co.uk>)
invalid resource manager ID in primary checkpoint record  ("ascot.moss@gmail.com" <ascot.moss@gmail.com>)
List pgsql-general
Oliver Kohll - Mailing Lists wrote
> select regexp_replace(sentence,'\*(.*?)\*','' || upper('\1'),'g') from
> sentences;

Yeah, you cannot embed a function-call result in the "replace with" section;
it has to be a literal (with the group insertion meta-sequences allowed of
course).

I see two possible approaches.

1) Use pl/perl (or some variant thereof) which has facilities to do just
this.
2) Use regexp_matches(,,'g') to explode the input string into its components
parts.  You can explode it so every character of the original string is in
the output with the different columns containing the "raw" and "to modify"
parts of each match.  This would be done in a sub-query and then in the
parent query you would "string_agg(...)" the matches back together while
manipulating the columns needed "i.e., string_agg(c1 || upper(c3))"

HTH

David J.




--
View this message in context:
http://postgresql.1045698.n5.nabble.com/Making-substrings-uppercase-tp5770096p5770108.html
Sent from the PostgreSQL - general mailing list archive at Nabble.com.


pgsql-general by date:

Previous
From: Adrian Klaver
Date:
Subject: Re: Hello,
Next
From: Marc Mamin
Date:
Subject: Re: Call for design: PostgreSQL mugs