Home > Software engineering >  PostgreSQL using substring
PostgreSQL using substring

Time:06-22

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

CodePudding user response:

demo:db<>fiddle

You can use split_part()

SELECT
    split_part(my_column, '.', 2) as country
FROM mytable
  • Related