Rajeev kumar
Rajeev kumar

Reputation: 163

Remove subsequent duplicate string in a column of table

I have a 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 to remove the subsequent duplicate letter from the column event_sequnce

so output table will be

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

How to write query to achieve this?

Upvotes: 3

Views: 76

Answers (1)

Arsen
Arsen

Reputation: 10951

You have to use regex for 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'), '\-\>$', '');

Upvotes: 1

Related Questions