Getting the last word from a Postgres string, declaratively

前端 未结 8 2388
无人及你
无人及你 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:40

    You can combine string_to_array and array_length

    select 
    (string_to_array(column_name, '.'))[array_length((string_to_array(column_name, '.')), 1)]
    from table_name;
    

    This will split the string in column_name into array using "." as delimiter and will give you the last part

提交回复
热议问题