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 1nRA7x-0008Qf-9K for pgsql-sql@arkaria.postgresql.org; Mon, 07 Mar 2022 09:58:05 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1nRA7w-00025x-7I for pgsql-sql@arkaria.postgresql.org; Mon, 07 Mar 2022 09:58:04 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1nRA7v-00025o-Qg for pgsql-sql@lists.postgresql.org; Mon, 07 Mar 2022 09:58:03 +0000 Received: from mail-pj1-x102e.google.com ([2607:f8b0:4864:20::102e]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1nRA7t-0003p1-8p for pgsql-sql@lists.postgresql.org; Mon, 07 Mar 2022 09:58:02 +0000 Received: by mail-pj1-x102e.google.com with SMTP id m22so12927230pja.0 for ; Mon, 07 Mar 2022 01:58:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=message-id:date:mime-version:user-agent:subject:content-language:to :references:from:in-reply-to; bh=8m2Y+qYD3p7DiZMnSZneB4UDrwO2Vq7qKwrBA6UtfdA=; b=ApsmAg9gqy9nLdNSjFsZF+Ui14gzoVYBTtSZ+mlBjKC+IYrvYZUd5dPxTqGf878/Nv l1Q3e2/jkqh2MOy7xvLz86xzteTbsJbWPq2PvJR2DPBpjUNNhish6Iu7crqkyUD7Szn8 H8rsJsLhfUulxY7tIwQ4f2jlCwawSHq8ARfD4dnK3lGhPc7po5bSh90PyG88kuNUM+K6 b6TPpUWPI33sHvfymYl/0xcvumwfJEWONLcp2nNNkYBhVGOBzpEftIlUZ6iMoFeednJm afufhU5My+MeIfLTaiSav9ApZb+VEl8hs8XoRp7WtCLZ0gbLDjEVQ05Gg4vgc9D6D0Yl T1Rw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:date:mime-version:user-agent:subject :content-language:to:references:from:in-reply-to; bh=8m2Y+qYD3p7DiZMnSZneB4UDrwO2Vq7qKwrBA6UtfdA=; b=57gqL7hY9xClyzuqxK0Zzd6/8TCX9H/8btRkxTwwoYtXDSvMrLe/LLjSKNjLVBVVVt aKCO6OfCrV72iHmXT+m1MFGx1vTYeqvK4Ndr7qoAOQNpAz0JN9mJTwi6EQHMndn8eKMp it5ysgdT0nBFxN+LsHWxHT9J5LcHAcel+23+qjxNRrwmL9/3IhrPgY2hHTlIXi2vGT3F xGWANaUQL6D4weJyueUUfgsDuv38bP+qYgHw07ilkh3fH8xP6hHq28wpsUcRepptliYs 02oGsNjMY8sDbUm48/ZZpswcQDP6Du39mBE43k5PWVSpG6R9SFWvr6QwSagA/TiE6F0i jKlg== X-Gm-Message-State: AOAM530W6xSXpGQUP1hD1OSMG6d0Poj1cuCugl8PSdRwoLc4PdswYLFh ClMQJlaO4jRP8mSfOxXjN6n4j/gVdRM= X-Google-Smtp-Source: ABdhPJwPzBcRE/C/fc4tZYvqtUy4d+vxZYngIx+Gmd+SCA9dfELRlZh7jqspT4HbdyLsyuT8vNHMmw== X-Received: by 2002:a17:902:8a97:b0:14a:c625:eb2d with SMTP id p23-20020a1709028a9700b0014ac625eb2dmr11232511plo.26.1646647079675; Mon, 07 Mar 2022 01:57:59 -0800 (PST) Received: from [10.128.71.194] ([155.98.131.2]) by smtp.gmail.com with ESMTPSA id o7-20020a63f147000000b00373facf1083sm11412676pgk.57.2022.03.07.01.57.58 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 07 Mar 2022 01:57:58 -0800 (PST) Content-Type: multipart/alternative; boundary="------------j8u6UgL3XBvN2mvy07RfT0k7" Message-ID: Date: Mon, 7 Mar 2022 02:57:57 -0700 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.6.1 Subject: Re: ERROR: extra data after last expected column Content-Language: en-CA To: pgsql-sql@lists.postgresql.org References: <775429fc5428ca2640f72f1d29f6e8ec90955e6c.camel@gmail.com> From: Rob Sargent In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk This is a multi-part message in MIME format. --------------j8u6UgL3XBvN2mvy07RfT0k7 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit On 3/7/22 02:08, Sándor Daku wrote: > > > On Mon, 7 Mar 2022 at 09:34, Scott Macri wrote: > > I'm trying to use the postgres copy command and getting, "extra data > after last expected column". > > All items in the DB are currently set to varchar(255) to make it > simple.  I've checked for hidden characters in the file and don't see > any.  All the other files I've processed with this exact command > worked > perfectly.  I've processed 10 other's so far.  The only difference I > notice is this one has significantly more columns. > > The number of columns in the DB (25) exactly match the number of > columns in the csv (25), which exactly match the number of columns > defined in my COPY command (25).  I've read practically every post on > the internet over the last two days containg this error and cannot > resolve it.  I am completely stumped at this point. > > It pukes after the 9th column every time no matter what I change. > > COPY option_details(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y) > FROM '/home/dump/my_csv.csv' WITH (FORMAT CSV, DELIMITER '|', ENCODING > 'UTF8'); > > Row one data in file is below: > item a | item b | item c | item d | item e | item f | item g | > item h | > item i | item j | item k | item l | item m | item n | item o | > item p | > item q | item r | item s | item t | item u | item v | item w | > item x | > item y > --- Line two would normally start here but no reason to show since > it's > failing above. --- > > I get the following error: > ERROR:  extra data after last expected column > CONTEXT:  COPY option_details, line 1: "item a|item b|item c|item > d|item e|item f|item g|item h|item i|..." > > > Any help or advice would be greatly appreciated.  Thank you very much. > > -- > Hacktorious > > > Hi, > > I pretty sure it doesn't fail after the  9th column, just the context > hint of the error message is cropped after that. > My guess is a sneaky '|' somewhere inside one of your field. > > Regards, > Sándor if Sándor  is correct this will show the offenders awk -F "|" '{if (NF != 25) print}' --------------j8u6UgL3XBvN2mvy07RfT0k7 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: 8bit
On 3/7/22 02:08, Sándor Daku wrote:


On Mon, 7 Mar 2022 at 09:34, Scott Macri <Scott@bitsnbytes.io> wrote:
I'm trying to use the postgres copy command and getting, "extra data
after last expected column".

All items in the DB are currently set to varchar(255) to make it
simple.  I've checked for hidden characters in the file and don't see
any.  All the other files I've processed with this exact command worked
perfectly.  I've processed 10 other's so far.  The only difference I
notice is this one has significantly more columns.

The number of columns in the DB (25) exactly match the number of
columns in the csv (25), which exactly match the number of columns
defined in my COPY command (25).  I've read practically every post on
the internet over the last two days containg this error and cannot
resolve it.  I am completely stumped at this point. 

It pukes after the 9th column every time no matter what I change.

COPY option_details(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y)
FROM '/home/dump/my_csv.csv' WITH (FORMAT CSV, DELIMITER '|', ENCODING
'UTF8');

Row one data in file is below:
item a | item b | item c | item d | item e | item f | item g | item h |
item i | item j | item k | item l | item m | item n | item o | item p |
item q | item r | item s | item t | item u | item v | item w | item x |
item y
--- Line two would normally start here but no reason to show since it's
failing above. ---

I get the following error:
ERROR:  extra data after last expected column
CONTEXT:  COPY option_details, line 1: "item a|item b|item c|item
d|item e|item f|item g|item h|item i|..."


Any help or advice would be greatly appreciated.  Thank you very much.

--
Hacktorious


Hi,

I pretty sure it doesn't fail after the  9th column, just the context hint of the error message is cropped after that.
My guess is a sneaky '|' somewhere inside one of your field.

Regards,
Sándor 
if Sándor  is correct this will show the offenders
awk -F "|" '{if (NF != 25) print}'


--------------j8u6UgL3XBvN2mvy07RfT0k7--