Search Postgresql Archives

Re: Removing Last field from CSV string

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 




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










[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]

  Powered by Linux