Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1iiAWJ-0005D5-PY for pgsql-docs@arkaria.postgresql.org; Fri, 20 Dec 2019 05:08:11 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1iiAWI-0008S1-Iq for pgsql-docs@arkaria.postgresql.org; Fri, 20 Dec 2019 05:08:10 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1iiAWI-0008Rt-8f for pgsql-docs@lists.postgresql.org; Fri, 20 Dec 2019 05:08:10 +0000 Received: from mail-qt1-x842.google.com ([2607:f8b0:4864:20::842]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1iiAWE-00051g-GZ for pgsql-docs@lists.postgresql.org; Fri, 20 Dec 2019 05:08:09 +0000 Received: by mail-qt1-x842.google.com with SMTP id d5so7200287qto.0 for ; Thu, 19 Dec 2019 21:08:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=4fIcdv6R8/Hkpn0npZrLN2B4IsZapUAmrBi3IkNhtkY=; b=uIh1JvduUxzU52UonIyh7AJx703UcMMNAtg+m+jFqpX35G5ZCnwzdVGUltToRvwImy HnSJ4jUFMEA1gzwlUFgDh6Amh8O3PSCaP42z3iTd8VSdyS0pMu4YeFART2hu696TEbrm buXCaZOQxbGKmIXZV+ryyQk+ttcXQeXOB8XRpu+82ESohray8xVj7d2XuEjnriAQFmu5 jc1Rp8MC0SyI4KS5AbpGDL+TUNkI7ET4qrJQ9zwnuUmgcg+JnDa+UEloxIlfuGfKNS/B c3ftHEL4pej3wosigl5szWRbNfvE2k1Mut1tkP/cAhiSAn4nevMcayzHCBZYgvUbqtdT ke5A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=4fIcdv6R8/Hkpn0npZrLN2B4IsZapUAmrBi3IkNhtkY=; b=Lmop2Rpl75oxKK4oqs7WjoYA5Ac7tErff76SMPAAcaHnFByWE8h3S+jM5rChViaNbn ymQ1VI/9LCvU3Oiqjhf999Kk7bSYv1Rtef3FZ3rRacBm/j+Fl6NtuxwdxBKXUHQFGxoV OxNBBfSFpS/olVC/iig++Vml0hWUNAVwqaGe0OCd0lvdTycpGR4O57WeBw/wA7qEbU3F W6M/mAuDVWzlb2kvm9RftbNT9H9/GPOHtUuzbWqwUOLcfFICWfEbIlcbbkvvAfXU7vhl 0kL9o/3dv152yb5zoqJVbuJNl1GE7XeA6Z/i0pVeuaxpzFZ8WbJtzcCGRzOeQ3FLsZKW 6Y4A== X-Gm-Message-State: APjAAAVwv+qguxvj+Rui513oE5zCOSXsKwLK7BHiApS1ojs32TF3d8/9 P8QAlrcFfy4OLvtNhAqAuFfP5vA8Xg8pkLNlo1M= X-Google-Smtp-Source: APXvYqyau3JuBMlUQYKktAD8zJ+7RQiPxGJf/nkEBWMUyFa8XdW+FtDQ8fCktSyGq5o3shu4TX+FihFik8Ql1X40LLg= X-Received: by 2002:ac8:7b4f:: with SMTP id m15mr10334901qtu.48.1576818484871; Thu, 19 Dec 2019 21:08:04 -0800 (PST) MIME-Version: 1.0 References: <157487729344.7213.14245726713444755296@wrigleys.postgresql.org> <4f3e2f301646d94ad33558e21fc77d5bf1ea1cdd.camel@cybertec.at> <20191219165340.GP30116@momjian.us> <12751.1576817197@sss.pgh.pa.us> In-Reply-To: <12751.1576817197@sss.pgh.pa.us> From: "David G. Johnston" Date: Thu, 19 Dec 2019 22:07:48 -0700 Message-ID: Subject: Re: COPY manual is ambiguous about column list To: Tom Lane Cc: Bruce Momjian , Pavlo Golub , Laurenz Albe , pgsql-docs@lists.postgresql.org Content-Type: multipart/alternative; boundary="000000000000aa8600059a1ba96b" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk --000000000000aa8600059a1ba96b Content-Type: text/plain; charset="UTF-8" On Thu, Dec 19, 2019 at 9:46 PM Tom Lane wrote: > Bruce Momjian writes: > > How is the attached patch? > > ! In COPY FROM, the number of columns specified > ! must match the number of fields in the file; any table columns not > ! specified in the COPY FROM column list will insert > ! their default values. > > Phrasing seems a bit weird to me: you've run two nearly independent > observations into one sentence. But s/; any/. Any/ might be enough > to fix it. > Seems better to simply talk about each form independently: If a list of columns is specified, COPY TO will only copy the data in the specified columns to the file. COPY FROM will, by position (i.e., the number of columns listed must match the number of columns in the file), match each file column to the named column in the table. Any additional columns present in the table will receive their default value. David J. --000000000000aa8600059a1ba96b Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
On Thu, Dec 19, 2019 at 9:46 PM Tom Lane <tgl@sss.pgh.pa.us> wrote:
Bruce Momjian <bruce@momjian.us> writes:
> How is the attached patch?

!=C2=A0 =C2=A0 In <command>COPY FROM</command>, the number of c= olumns specified
!=C2=A0 =C2=A0 must match the number of fields in the file;=C2=A0 any table= columns not
!=C2=A0 =C2=A0 specified in the <command>COPY FROM</command> co= lumn list will insert
!=C2=A0 =C2=A0 their default values.

Phrasing seems a bit weird to me: you've run two nearly independent
observations into one sentence.=C2=A0 But s/; any/. Any/ might be enough to fix it.

Seems better to simply talk ab= out each form independently:

If a list of columns is s= pecified, <command>COPY TO</command> will only copy the data in= the specified columns to the file.=C2=A0 <command>COPY FROM</comm= and> will, by position (i.e., the number of columns listed must match th= e number of columns in the file), match each file column to the named colum= n in the table.=C2=A0 Any additional columns present in the table will rece= ive their default value.

David J.

--000000000000aa8600059a1ba96b--