I want to split a string using a colon as delimiter and select 2nd and 3rd part.
Table:
|asdsc:dcdes:dcd|
|dcfd:drfe:regf |
Expected output:
|dcdes|
|drfe|
and also third column:
|dcd |
|regf|
                Use split_part():
with my_table(str) as (
    values 
    ('asdsc:dcdes:dcd'),
    ('dcfd:drfe:regf')
)
select 
    str, 
    split_part(str, ':', 2) as part_no_2, 
    split_part(str, ':', 3) as part_no_3
from my_table
       str       | part_no_2 | part_no_3 
-----------------+-----------+-----------
 asdsc:dcdes:dcd | dcdes     | dcd
 dcfd:drfe:regf  | drfe      | regf
(2 rows)    
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With