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 1o0ZsW-0004Bz-Fz for pgsql-hackers@arkaria.postgresql.org; Mon, 13 Jun 2022 02:32:32 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1o0ZsV-0000u5-8E for pgsql-hackers@arkaria.postgresql.org; Mon, 13 Jun 2022 02:32:31 +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 1o0ZsU-0000ql-Oz for pgsql-hackers@lists.postgresql.org; Mon, 13 Jun 2022 02:32:30 +0000 Received: from mail-pg1-x529.google.com ([2607:f8b0:4864:20::529]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1o0ZsP-0005v7-0Z for pgsql-hackers@postgresql.org; Mon, 13 Jun 2022 02:32:29 +0000 Received: by mail-pg1-x529.google.com with SMTP id 129so4383292pgc.2 for ; Sun, 12 Jun 2022 19:32:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=aD7od8cYsPmA4icG07DHMN0BnLcQC9gwGPPY/l88Ssk=; b=SJt7CYBrENIQ4PPMRCETPlSgml15A9+RDJOIGjifh4tf66wrDic515MxvLzVvk5W6f CJAraKfVdnRo6Fs7ItwzvP9EKMHzbQtkkRWZ1rYAxz3qO06J3w9nrV4gNgeade5X3XXk bYL6CwFPp2P1Q94ybC95qa9NzKTWIH8QIelC1S6HzEbBUtEFEoGukuonRzCkhrjcA7qs jhkcTRLsPUBBjieEUCeXEFPlK9FZn1e9oqJvZzV79EkBsmKfXDNzX6i2l+fjvD7UZsv1 IvtmdCbNPFgYyeuGzCs133kRagVy/pb9jKn7P7pgCx/5pSmwGN76A9Bj1eHNa9F8fm7v i2Qg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=aD7od8cYsPmA4icG07DHMN0BnLcQC9gwGPPY/l88Ssk=; b=gadvI3PcRYIevm8JOB+yCfqHHKnBkQ2UuUbh/DlGrRCokxXAAUtciNJWN94eIJGeHJ 0gVMeU/4G3eEVntE8eVpNEgDgJWq/dqVbXNsZ1e8JWrGvsvNsfJL9WISlPTy0P3S8q4X 60GH8TYZzMSKb42oR9FwwSk9EX/naG2qB1lf4fTkZx5nMGiycy1aRInw0H9NGEYxOsK+ +XequNmC+6Jxneo6QrH5tzGYyCieG/rEQl8WEzqckthyxTxhjTQBmw/LR4Le8AVLg/46 7oT4rzwD+xArtvvXOiIODD/FnaXPhsK4VO8lxj/m7BbIbvoHIscgExfM1WxczorHxYt2 NObA== X-Gm-Message-State: AOAM530/YTq4TuyXJyqS/zd9eP0pJ8miBHi9Oxvq1cvyytDZw3V6Kkbj PivN1LBPyjBLzFeyJLvM2Jg= X-Google-Smtp-Source: ABdhPJx0XX2i3K3VDZ5eLiiCppE7c9atZAk89i+AOP3+ryZYhB9ArB3RLzZAGarVjRhRVva3g1nXQQ== X-Received: by 2002:a05:6a02:19b:b0:39d:cfa:5cda with SMTP id bj27-20020a056a02019b00b0039d0cfa5cdamr49675785pgb.175.1655087543424; Sun, 12 Jun 2022 19:32:23 -0700 (PDT) Received: from jrouhaud (2001-b011-1006-18e1-959f-bb14-8391-5ba3.dynamic-ip6.hinet.net. [2001:b011:1006:18e1:959f:bb14:8391:5ba3]) by smtp.gmail.com with ESMTPSA id w6-20020a639346000000b003fdc7e490a6sm4087787pgm.20.2022.06.12.19.32.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 12 Jun 2022 19:32:22 -0700 (PDT) Date: Mon, 13 Jun 2022 10:32:13 +0800 From: Julien Rouhaud To: Andrew Dunstan Cc: Peter Eisentraut , Greg Stark , =?utf-8?B?UsOpbWk=?= Lapeyre , Zhihong Yu , David Steele , Michael Paquier , vignesh C , PostgreSQL-development , Daniel Verite Subject: Re: Add header support to text format and matching feature Message-ID: <20220613023213.bj7qjnplvgfmx522@jrouhaud> References: <94FDDB44-A608-4C75-A733-9F8FC5180D6B@lenstra.fr> <4816b2df-646f-dc19-e5cc-4bfbd04c0e43@enterprisedb.com> <07891B9D-2140-4C06-AF96-C14F1E1B0E8E@lenstra.fr> <8eba1968-9503-5be7-b473-37383f17bb72@enterprisedb.com> <206ac69a-4e47-c49a-66ae-e748c339ba35@enterprisedb.com> <20220607154744.vvmitnqhyxrne5ms@jrouhaud> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="7dpw752g5cnup6cx" Content-Disposition: inline In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --7dpw752g5cnup6cx Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Hi, On Sun, Jun 12, 2022 at 09:36:13AM -0400, Andrew Dunstan wrote: > > On 2022-06-07 Tu 11:47, Julien Rouhaud wrote: > > > > First, probably nitpicking, the HEADER MATCH is allowed for COPY TO, is that > > expected? The documentation isn't really explicit about it, but there's > > nothing to match when exporting data it's a bit surprising. I'm not opposed to > > have HEADER MATCH means HEADER ON for COPY TO, as as-is one can easily reuse > > the commands history, but maybe it should be clearly documented? > > > I think it makes more sense to have a sanity check to prevent HEADER > MATCH with COPY TO. I'm fine with it. I added such a check and mentioned it in the documentation. > > Then, apparently HEADER MATCH doesn't let you do sanity checks against a custom > > column list. This one looks like a clear oversight, as something like that > > should be entirely valid IMHO: > > > > CREATE TABLE tbl(col1 int, col2 int); > > COPY tbl (col2, col1) TO '/path/to/file' WITH (HEADER MATCH); > > COPY tbl (col2, col1) FROM '/path/to/file' WITH (HEADER MATCH); > > > > but right now it errors out with: > > > > ERROR: column name mismatch in header line field 1: got "col1", expected "col2" > > > > Note that the error message is bogus if you specify attributes in a > > different order from the relation, as the code is mixing access to the tuple > > desc and access to the raw fields with the same offset. > > [...] > I think it should, but a temporary alternative would be to forbid HEADER > MATCH with explicit column lists until we can make it work right. I think it would still be problematic if the target table has dropped columns. Fortunately, as I initially thought the problem is only due to a thinko in the original commit which used a wrong variable for the raw_fields offset. Once fixed (attached v1) I didn't see any other problem in the rest of the logic and all the added regression tests work as expected. --7dpw752g5cnup6cx Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v1-0001-Fix-processing-of-header-match-option-for-COPY.patch"