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 1nRWmG-0004wB-G9 for pgsql-sql@arkaria.postgresql.org; Tue, 08 Mar 2022 10:09:12 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1nRWmF-0004VA-G8 for pgsql-sql@arkaria.postgresql.org; Tue, 08 Mar 2022 10:09:11 +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 1nRP0J-0006mQ-Lm for pgsql-sql@lists.postgresql.org; Tue, 08 Mar 2022 01:51:11 +0000 Received: from mail-qv1-xf30.google.com ([2607:f8b0:4864:20::f30]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1nRP0G-0002s8-Mh for pgsql-sql@lists.postgresql.org; Tue, 08 Mar 2022 01:51:10 +0000 Received: by mail-qv1-xf30.google.com with SMTP id iv12so12098800qvb.6 for ; Mon, 07 Mar 2022 17:51:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=sender:from:message-id:subject:reply-to:to:cc:date:in-reply-to :references:organization:user-agent:mime-version :content-transfer-encoding; bh=A+Wq+gqTM8DMLiWudQd+f7EvG6EsqVvBAkM4k21McI0=; b=Hdzzc2V4HCEQSPghx/PV5vMmNfXXNn8H3V2QjH4E2Paia1xFvd4TF5QM/5QVGFxE+I IuMJbiD7qzGj8IjQ0sK5bwZIqDQnoTI1R5mRMYBH5Cw6EHj4vJMif8PgxU+Udw1Vhhrq Qa0D6BbHLbML53eREQoVzYExWDztcdeXGOV584M+3Wl7AQHI+oQEBDgD0h4kK4CnniV4 U72kuPUTxIW80hiNTgD8FUmeAi31oCK4YMrt7arvJvBUpbiplpaGqkhVq9cQBqvyCQfS maa65SgEzMSOPBmLR9gHQSyBf6jCQBh25Of38YO0hrEYkta4Zf6f6QW2EK4p/AxLaPxa SFtg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:sender:from:message-id:subject:reply-to:to:cc :date:in-reply-to:references:organization:user-agent:mime-version :content-transfer-encoding; bh=A+Wq+gqTM8DMLiWudQd+f7EvG6EsqVvBAkM4k21McI0=; b=JQdMJtLhHYIITpbglV4YSRxHp1Tav7HMRR0NHJksf/E2+WyKwk1a/xq4xaB3/fIvK3 3+hg07E0loe+1frYwxFchK/9iNW2BtVPP+9R24lbgn40Mo7ZO1nzboSXlHhENFBGkYj8 QyNjqbSDETL7UzGXdEiBzGbvYYsMFc+byBkW1iDzjwFDoQgHp6XeNqvRstV15mBRSJvt JQzPqP4fEv6VL427lumVijkjDf7n9oQSuVJ4HD6mTYRfdHAuun81jTLAIh+Nw1a9A+rD LU1uh21dGwSswKHbhpT5exgk3IA4lHl+u9NUIyV0BPlLpV3U9IM7cvAmT4Yr7Vx/u0ur BTmw== X-Gm-Message-State: AOAM532d4I04CG2LmRJRNdxJbykATEtF/hgFt6lK7HjS9SCGTV0vjxeo Vlz6HF8GK+rsVGil5vF0zsc= X-Google-Smtp-Source: ABdhPJzV/XBVgVTNbHsuTPGCbqYrP4Ah5RoduRVyDK0oNtn/kbpq2xMQ44SSFCpkqUJz8pGFowvxMQ== X-Received: by 2002:a05:6214:e43:b0:435:a753:2434 with SMTP id o3-20020a0562140e4300b00435a7532434mr1848889qvc.40.1646704267783; Mon, 07 Mar 2022 17:51:07 -0800 (PST) Received: from [10.132.0.6] ([45.132.227.243]) by smtp.gmail.com with ESMTPSA id g14-20020ae9e10e000000b0067b520a01afsm922922qkm.108.2022.03.07.17.51.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Mar 2022 17:51:07 -0800 (PST) Sender: Scott Macri From: Scott Macri X-Google-Original-From: Scott Macri Message-ID: <354e10f466876aad50a77fa6fcb49206c29e678f.camel@gmail.com> Subject: Re: ERROR: extra data after last expected column Reply-To: Scott@BITSnBYTES.io To: Steve Midgley Cc: Rob Sargent , pgsql-sql Date: Mon, 07 Mar 2022 20:51:06 -0500 In-Reply-To: References: <775429fc5428ca2640f72f1d29f6e8ec90955e6c.camel@gmail.com> Organization: BITSnBYTES Content-Type: text/plain; charset="UTF-8" User-Agent: Evolution 3.42.4 (by Flathub.org)) MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk It looks like it might have something to do with the line length. All the output from the AWK command are a continuation of the line above it. There is no line break, however. I'm investigating now. On Mon, 2022-03-07 at 15:56 -0800, Steve Midgley wrote: > > > On Mon, Mar 7, 2022 at 3:54 PM Steve Midgley > wrote: > > > > On Mon, Mar 7, 2022 at 3:34 PM scott macri > > wrote: > > > No luck > > > > > > On Mon, Mar 7, 2022, 4:58 AM Rob Sargent > > > wrote: > > > > 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}' > > > >   > > > >   > > > > > > > > > Can you send the CSV file that is causing the problem as a CSV file > > attachment so some of us can try this as a full reproduction? I > > don't want to copy/paste the sample line from the text of the email > > as it seems like that wouldn't be a good replication path for such > > a weird bug.. > > > > > > > Also, have you tried ASCII encoding or something very permissive like > that? If that works but UTF-8 doesn't, it might be a clue that > there's an errant char buried in your CSV file. Also, maybe try > looking at your CSV file with a hex editor.. The weirdest stuff can > turn up in "wild caught" CSVs..  -- Hacktorious