Search Postgresql Archives

Re: Regular expression to UPPER() a lower case string

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 2022-12-10 15:37:01 +0000, Eagna wrote:
> Hi, and thanks for all of the input - I think I'm beginning to grok it.

I'm not so sure about that

> As far as I can see, I can only do what I want by using the following.
> 
> If there's a monthly prize on this list for the most insanely
> contrived piece of code, I think this is a strong contender:
> 
> test.x = 'abc'
> 
> SELECT
>   UPPER(REGEXP_REPLACE(x, '(.)(.)(.)', '\1')) ||
>   UPPER(REGEXP_REPLACE(x, '(.)(.)(.)', '\2')) ||
>   UPPER(REGEXP_REPLACE(x, '(.)(.)(.)', '\3'))
> FROM test;
> 
> Result: ABC 

I don't think this does what you want it to do:

wds=> SELECT x,
  UPPER(REGEXP_REPLACE(x, '(.)(.)(.)', '\1')) ||
  UPPER(REGEXP_REPLACE(x, '(.)(.)(.)', '\2')) ||
  UPPER(REGEXP_REPLACE(x, '(.)(.)(.)', '\3'))
FROM test;
╔═════════════╤═════════════════════════════╗
║      x      │          ?column?           ║
╟─────────────┼─────────────────────────────╢
║ abc_def_ghi │ A_DEF_GHIB_DEF_GHIC_DEF_GHI ║
╚═════════════╧═════════════════════════════╝

(I admit it took me at least a minute to figure out what was happening
here)

        hp

-- 
   _  | Peter J. Holzer    | Story must make more sense than reality.
|_|_) |                    |
| |   | hjp@xxxxxx         |    -- Charles Stross, "Creative writing
__/   | http://www.hjp.at/ |       challenge!"

Attachment: signature.asc
Description: PGP signature


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]

  Powered by Linux