may help you . I have a column like the one below. The last two sets of numbers are date and time. I want to create date-time column by extracting values from the column. , This substring extracts the date time part from your string.
code :
SELECT substring(col_name,regexp_instr(col_name,'-',1,regexp_count(col_name,'-')-1)+1,
regexp_instr(col_name,'.json',1)-regexp_instr(col_name,'-',1,regexp_count(col_name,'-')-1)-1)
WITH test(col_name) AS (
SELECT '1002206391240385-sponsoredProducts-SameDayPull-20190627-012313.json'::TEXT
)
SELECT col_name,
substring(col_name,regexp_instr(col_name,'-',1,regexp_count(col_name,'-')-1)+1,
regexp_instr(col_name,'.json',1)-regexp_instr(col_name,'-',1,regexp_count(col_name,'-')-1)-1) datetime
FROM test
col_name datetime
1002206391240385-sponsoredProducts-SameDayPull-20190627-012313.json 20190627-012313