Removing Last field from CSV string

From: Alex Magnum <magnum11200(at)gmail(dot)com>
To: Postgres General <pgsql-general(at)postgresql(dot)org>
Subject: Removing Last field from CSV string
Date: 2020-05-16 15:18:57
Message-ID: CA+cR4ze=Qq9V1i4NGNjCP_=O0bduM8KVse1oCVeszsR8LmVyzA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

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 you
Alex

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Rob Sargent 2020-05-16 16:03:21 Re: schema agnostic functions in language sql
Previous Message David G. Johnston 2020-05-16 15:12:58 Re: schema agnostic functions in language sql