This query works in Oracle please let me know how to extract text in postgresql
Select regexp_sustr('abc,afgg,afff,eef esfg eg,gegg,egegeg,vgb,grgg','[^,]+',1,5)
This query works in Oracle please let me know how to extract text in postgresql
Select regexp_sustr('abc,afgg,afff,eef esfg eg,gegg,egegeg,vgb,grgg','[^,]+',1,5)
2
Answers
You could use a regex replacement trick here:
Demo
This approach strips off the first 3 CSV terms and the 4th comma until the end of the string.
Use
split_part
instead to efficiently obtain the n-th field given a delimiter:Demo: https://dbfiddle.uk/?rdbms=postgres_14&fiddle=5a3dd70a3793e3588d300bbb61dcf0b6
If you insist on using regex, the equivalent function to
REGEXP_SUBSTR
in PostgreSQL isregexp_matches
:Demo: https://dbfiddle.uk/?rdbms=postgres_14&fiddle=72b728f15fe1d8b7a5c0cec8f32790fd