sql - PostgreSQL get last value in a comma separated list of values -
in postgresql table have column has values
ax,b,c a,bd x,y j,k,l,m,n
in short , have few comma separated strings in column each record. wanted last 1 in each record. ended this.
select id, reverse(substr(reverse(mycolumn),1,position(',' in reverse(mycolumn)))) mytable order id ;
is there easier way?
with regexp_replace
:
select id, regexp_replace(mycolumn, '.*,', '') mytable order id;
Comments
Post a Comment