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

Get the 3rd part of the string in Postgres

I have data like,

ab-volt-ssn-dev
ab-volt-lnid-dev
ab-volt-ssn-hamp-dev
ab-volt-cf-apnt-test

I need output to be like,

ssn
lnid
ssn
cf

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 can use split_part()

select split_part('ab-volt-ssn-hamp-dev', '-', 3);

If you need to access multiple parts, then converting it to an array might be easier:

select elements[1],
       elements[2],
       elements[3],
       elements[4]
from (
   select string_to_array(the_column, '-') as elements
   from the_table
) t;          
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