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

Popular posts from this blog

php - regexp cyrillic filename not matches -

c# - OpenXML hanging while writing elements -

sql - Select Query has unexpected multiple records (MS Access) -