1

I have a column with strings like '006_THR'; '1003_ER'; '100_THREE' and i want to put all string before "_" in a column and all string after "_" in a other column.

 col         col1     col2
006_THR      006       THR
1003_ER      1003      ER  
100_THRE     100       THRE 

Thank you!

1 Answer 1

3

How about split_part():

select col, split_part(col, '_', 1) as col1, split_part(col, '_', 2) as col2
from t;
Sign up to request clarification or add additional context in comments.

2 Comments

I struggled with substring and strpos. I didn't know about split_part. Thank you!
@Lucian . . . If you like split_part() you'll just love regexp_split_to_table() and regexp_split_to_array()!

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.