Re: Removing Last field from CSV string

From: Samuel Roseman <muelrose(at)yahoo(dot)com>
To: Postgres General <pgsql-general(at)postgresql(dot)org>, Alex Magnum <magnum11200(at)gmail(dot)com>
Subject: Re: Removing Last field from CSV string
Date: 2020-05-20 05:21:09
Message-ID: 759976875.1953487.1589952069934@mail.yahoo.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Regular expressions, in my opinion, can be a very powerful text search and replace engine if you know how to use it.Feel free to enhance what I provided below; it seems to work for the example you provided.
postgres=# select regexp_replace(substring('Class V,Class VI,Class VII,Competitive Exam,Class VIII,Class X,Class XI,Class IX,Class XII',1,60),'(.*),\w+','\1');                     regexp_replace                     -------------------------------------------------------- Class V,Class VI,Class VII,Competitive Exam,Class VIII(1 row)

Regards,

PflugerGeek
On Saturday, May 16, 2020, 10:19:28 AM CDT, Alex Magnum <magnum11200(at)gmail(dot)com> wrote:

Hi,
I have a string that I want to cut to 60 char and then remove the last field and comma.

substring('Class V,Class VI,Class VII,Competitive Exam,Class VIII,Class X,Class XI,Class IX,Class XII',1,60);

substring | Class V,Class VI,Class VII,Competitive Exam,Class VIII,Class

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.
Thank youAlex

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Pavel Stehule 2020-05-20 08:06:02 Re: Q: Comparing PostgreSQL and Oracle
Previous Message Kyotaro Horiguchi 2020-05-20 01:21:00 Re: Configuring more than one hot standby server