Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to return all capital letters in row postgresql

I’ve got a simple table, primary key and name.
The string always starts with a capital letter but could have more capital letters than just the first character. I want to return all the uppercase characters in the name.

select
    (select substring(name, '([A-Z])') name)
from cust

This returns just the first capital letter. How can I achieve this?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

You may use a regex replacement on the name to remove any character which is not an uppercase letter:

SELECT name, REGEXP_REPLACE(name, '[^A-Z]+', '', 'g') AS caps
FROM cust;
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading