Reputation: 163
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
Reputation: 10951
You have to use regex for it:
select regexp_replace('d->d->a->d->c->a->a->c', '(\w\-\>)\1+', '\1', 'g');
Update version
select regexp_replace(regexp_replace(textcat('d->d->a->d->c->a->a->c->c', '->'), '(\w\-\>)\1+', '\1', 'g'), '\-\>$', '');
Upvotes: 1