Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

POSTGRESQL: remove all characters before a specific character

I have values like 6864#21, 1a2b#3598 in my database. I'm trying to extract just the portion before and after the #, so I would get something like

col1  | col2
-----------
6864  | 21
1a2b  | 3598

I tried

REPLACE('123#89', '%#', '')

but that just resulted in 123#89. Does anyone know a way I can do this?

like image 638
user3813773 Avatar asked Dec 06 '22 00:12

user3813773


1 Answers

Try this:

SELECT split_part('123#23','#',1) AS "COL1",split_part('123#23','#',2) AS "COL2"
like image 135
Ilesh Patel Avatar answered Mar 05 '23 10:03

Ilesh Patel