There are a number of question related to this and the answer is to use split_part()
. For example:
emulating MySQL's substring_index() in PGSQL
Mysql`s SUBSTRING_INDEX equivalent in postgresql
I'm not getting the same behavior, however. I'm trying to figure out how to get the following functionality in Postgres.
If you have a string that looks like:
+------------------------------------------+
| string |
+------------------------------------------+
| A_123, B_123, C_123, D_123, E_123, F_123 |
+------------------------------------------+
MySQL will return the following with the given statement:
mysql> select SUBSTRING_INDEX(string, ',', 4) AS test FROM tbl;
+----------------------------+
| test |
+----------------------------+
| A_123, B_123, C_123, D_123 |
+----------------------------+
PostgreSQL will return the following with the given statement:
mysql> select split_part(string, ',', 4) AS test FROM tbl;
+-------+
| test |
+-------+
| D_123 |
+-------+
Is there a similar function or just implementing a function like this?