Re: Removing Last field from CSV string

From: Michael Nolan <htfoot(at)gmail(dot)com>
To: Alex Magnum <magnum11200(at)gmail(dot)com>
Cc: Postgres General <pgsql-general(at)postgresql(dot)org>
Subject: Re: Removing Last field from CSV string
Date: 2020-05-16 17:29:34
Message-ID: CAOzAqu+7uFb96+b7SJ_Hf_NfhR7u-q2i_bXNwVgwH3c288adWg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Sat, May 16, 2020 at 10:19 AM 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.
>
> You should be able to write a posix patter that does this, you want to
> keep everything except a comma followed by 0 or more non-commas and the end
> of the string boundary to make sure it gets just the last such match.
>
--
Mike Nolan
nolan(at)tssi(dot)com

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2020-05-16 17:44:34 Re: template0 needing vacuum freeze?
Previous Message Don Seiler 2020-05-16 17:19:13 template0 needing vacuum freeze?