Getting the last word from a Postgres string, declaratively

前端 未结 8 2567
无人及你
无人及你 2021-02-07 00:18

[EDIT] original title of this question was \"Getting the last element of a Postgres array, declaratively\"

How to obtain the last element of the array in Postgr

8条回答
  •  清歌不尽
    2021-02-07 00:34

    If I understand your question correctly you have a string and you're first splitting it on some separator and then afterwards finding the last element of the array and discarding the rest.

    You could miss out the middle man and get the last element directly:

    SELECT regexp_replace('foo bar baz', '^.* ', '')
    

    Result:

    baz
    

提交回复
热议问题