Re: Removing Last field from CSV string
От | Christian Ramseyer |
---|---|
Тема | Re: Removing Last field from CSV string |
Дата | |
Msg-id | 9e874908-71d4-b01b-fae4-b61a25453899@networkz.ch обсуждение исходный текст |
Ответ на | Removing Last field from CSV string (Alex Magnum <magnum11200@gmail.com>) |
Список | pgsql-general |
On 16.05.20 17:18, Alex Magnum wrote: > Now I try to remove the last field and comma ",Class" > > To get Class V,Class VI,Class VII,Competitive Exam,Class VIII > > Is there a function or easy way to do this? > Any help would be appreciated. > Hi Alex Many options to do this with regexp_replace, here's one way: with test as ( select 'Class VII,Competitive Exam,Class VIII,Class' as str union select 'Class VIIx,Competitive Exam22,Class VIIIabc,Classx' ) select str, regexp_replace(str, '^(.*),(.*?)$', '\1') res from test; |str |res | |------------------------------------------------------| |Class VII,Competitive Exam,Class VIII,Class |Class VII,Competitive Exam,Class VIII |------------------------------------------------------| |Class VIIx,Competitive Exam22,Class VIIIabc,Classx |Class VIIx,Competitive Exam22,Class VIIIabc | (I cut some columns at the start to better fit email width) Cheers Christian -- Christian Ramseyer, netnea ag Network Management. Security. OpenSource. https://www.netnea.com
В списке pgsql-general по дате отправления: