1

I have a column with values source:destination:city:street:number and i would like to get only the city without : .

How can I do that?

Thanks in advance

1 Answer 1

3

How can I do that?

works in both BigQuery dialects: Legacy and Standard SQL

SELECT 
  REGEXP_EXTRACT('source:destination:city:street:number', r'(?:.+:){2}(.+)(?::.+){2}')  

see more for REGEXP_EXTRACT and re2 syntax

if I need the first word after source: for example?

SELECT 
  REGEXP_EXTRACT('source:destination:city:street:number', r'(?:.+:){1}(.+)(?::.+){3}')  

There are many options here for you depends on what exactly you need
Another one is below (BigQuery Legacy SQL)

SELECT 
  NTH(1, SPLIT(text,':')) AS source,
  NTH(2, SPLIT(text,':')) AS destination,
  NTH(3, SPLIT(text,':')) AS city,
  NTH(4, SPLIT(text,':')) AS street,
  NTH(5, SPLIT(text,':')) AS number
FROM (
  SELECT 'source:destination:city:street:number' AS text
)
Sign up to request clarification or add additional context in comments.

1 Comment

Thank for your answer, and if I need the first word after source: for example?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.