Re: Removing Last field from CSV string

From: Steve Litt <slitt(at)troubleshooters(dot)com>
To: pgsql-general(at)lists(dot)postgresql(dot)org
Subject: Re: Removing Last field from CSV string
Date: 2020-05-18 02:07:15
Message-ID: 20200517220715.4bc7fa2b@mydesk.domain.cxm
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Sat, 16 May 2020 23:18:57 +0800
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 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

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Ram Pratap Maurya 2020-05-18 05:06:17 pg_basebackup: child process exited with error 1
Previous Message Steve Litt 2020-05-18 01:55:09 Re: Inherited an 18TB DB & need to backup