sql - Remove subsequent duplicate string in a column of table -


i have table named event

id     event_sequnce 1      a->c->b->b->b->c->b 2      d->d->a->d->c->a->a->c 

i want remove subsequent duplicate letter column event_sequnce

so output table be

id   event_sequnce 1    a->c->b->c->b 2    d->a->d->c->a->c 

how write query achieve this?

you have use regex it:

select regexp_replace('d->d->a->d->c->a->a->c', '(\w\-\>)\1+', '\1', 'g'); 

enter image description here

update version

select regexp_replace(regexp_replace(textcat('d->d->a->d->c->a->a->c->c', '->'), '(\w\-\>)\1+', '\1', 'g'), '\-\>$', ''); 

Comments

Popular posts from this blog

django - (fields.E300) Field defines a relation with model 'AbstractEmailUser' which is either not installed, or is abstract -

matlab - error with cyclic autocorrelation function -

php - Using grpc in Laravel, "Class 'Grpc\ChannelCredentials' not found." -