Postgres line splitting

I have a line with some spaces in it and I would like to split it into the last space and return part of the line before this space. Does Postgres support this? I could not solve this with the usual functions like split_part.
Example: "fort worth tx" → "fort worth"

+3
source share
2 answers

it does not break the original string, but does what you want:

SELECT regexp_replace('fort worth tx', '\\s\\S+$', '');
+3
source

You will need to write the plpgsql function to accomplish this. Look here for a function to find the last occurrence of a string.

0
source

Source: https://habr.com/ru/post/1766453/


All Articles