From: Steve Litt <slitt@troubleshooters.com>
To: pgsql-general@lists.postgresql.org
Subject: Re: Removing Last field from CSV string
Date: Sun, 17 May 2020 22:07:15 -0400
Message-ID: <20200517220715.4bc7fa2b@mydesk.domain.cxm> (raw)
In-Reply-To: <CA+cR4ze=Qq9V1i4NGNjCP_=O0bduM8KVse1oCVeszsR8LmVyzA@mail.gmail.com>
References: <CA+cR4ze=Qq9V1i4NGNjCP_=O0bduM8KVse1oCVeszsR8LmVyzA@mail.gmail.com>
On Sat, 16 May 2020 23:18:57 +0800
Alex Magnum <magnum11200@gmail.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 you
> Alex
Assuming the CSV strings are in a file, my first thought would be to
get rid of the final field using AWK, and feed that into your import.
SteveT
Steve Litt
May 2020 featured book: Troubleshooting Techniques
of the Successful Technologist
http://www.troubleshooters.com/techniques
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-general@postgresql.org
Cc: slitt@troubleshooters.com
Subject: Re: Removing Last field from CSV string
In-Reply-To: <20200517220715.4bc7fa2b@mydesk.domain.cxm>
References: <CA+cR4ze=Qq9V1i4NGNjCP_=O0bduM8KVse1oCVeszsR8LmVyzA@mail.gmail.com> <20200517220715.4bc7fa2b@mydesk.domain.cxm>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox