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

PostgreSQL using substring

I’m trying to create a query where it extracts the country only from a column. The column looks as follow.

Label:
456.United_States.NYC
4589.United_States
789.United_States.NYC.Manhattan_Level
506.India.Bangladesh_3

>Solution :

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

demo:db<>fiddle

You can use split_part()

SELECT
    split_part(my_column, '.', 2) as country
FROM mytable
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