Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jaVBc-0006D9-P5 for pgsql-general@arkaria.postgresql.org; Mon, 18 May 2020 02:07:24 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1jaVBb-0000i4-BF for pgsql-general@arkaria.postgresql.org; Mon, 18 May 2020 02:07:23 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jaVBb-0000fP-3C for pgsql-general@lists.postgresql.org; Mon, 18 May 2020 02:07:23 +0000 Received: from troubleshooters.com ([69.5.27.237]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jaVBY-0006U1-6t for pgsql-general@lists.postgresql.org; Mon, 18 May 2020 02:07:22 +0000 Received: (qmail 14154 invoked from network); 18 May 2020 02:07:16 -0000 DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; h=X-Originating-IP:Date:From:To:Subject:Message-ID:In-Reply-To:References:MIME-Version:Content-Type:Content-Transfer-Encoding; s=default; d=troubleshooters.com; b=aoEKTEOAMf36trwXambrpt/fzQLYUDtjFZRgFvd+/2QFbs2pNdDZGwsAnIi8pe1rq/rSiSq7EpxlWBNfh/82FNUdH45To9AhLJbivSHoapK5+L/5TqYt+0i77VJ70cG08MTipanS0ZAowt/+SPw8YjHyWRNfhsTkkFnBKkfMQa8=; DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/simple; d=troubleshooters.com; s=default; t=1589767636; bh=je9ry/HMmi9Myn26VWyRLRZtG6I=; l=936; h=X-Originating-IP:Date:From:To:Subject:Message-ID:In-Reply-To: References:MIME-Version:Content-Type:Content-Transfer-Encoding; b=Tasl5HcJuj4vUlu8PV/eKbK+eQfz8XAqEuKC7CVwHPyL/CXUkuIIA4Wg6iic/B6wF QOkG2nCBkJdA//1UamYbS8zRgFZ92MmycICMcMFALMsfiultL/8sM9mfl6IDT7kLIV f+eTugz4vAMDBxNQifHOjGD+2t/iz9pQKhmZlOJw= X-Originating-IP: [72.188.224.222] Date: Sun, 17 May 2020 22:07:15 -0400 From: Steve Litt To: pgsql-general@lists.postgresql.org Subject: Re: Removing Last field from CSV string Message-ID: <20200517220715.4bc7fa2b@mydesk.domain.cxm> In-Reply-To: References: MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On Sat, 16 May 2020 23:18:57 +0800 Alex Magnum 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