Re: COPY manual is ambiguous about column list
"David G. Johnston" <[email protected]> Fri, 20 Dec 2019 07:29:33 -0700
| Newsgroups | gmane.comp.db.postgresql.devel.documentation |
|---|---|
| Message-ID | <CAKFQuwa5RToC3+mbVGydTJZsqZhACK+F_CDtpcrCzxqwGXk6Cg@mail.gmail.com> |
--000000000000a9e589059a2382c8 Content-Type: text/plain; charset="UTF-8" On Fri, Dec 20, 2019 at 7:13 AM Tom Lane <[email protected]> wrote: > Bruce Momjian <[email protected]> writes: > > OK, how is this? > > I do not like the phrasing of > > If a column list is > specified in <command>COPY FROM</command>, the number and position of > the columns must match those fields in the file. > > I'm not quite sure why, but that reads to me as implying that the COPY > will identify columns of the file by name and match them up. Or at > least it could be read that way by somebody who was predisposed to > believe it. I'd go with something more like > > If a column list is > specified in <command>COPY FROM</command>, only the listed columns > are read from the file (whose fields must match the column list). > This has the same "match by name" possibility when I read it... I don't see the benefit of repeating "If a column list is specified" a second time in the three sentence paragraph. To a lesser extent the same goes for the second repetition of COPY FROM. I agree with the general goal of trying to get rid of the parenthetical; to that end: <command>COPY FROM</command> will match all listed columns in the table to *all* file columns by position. That sufficiently implies the "must have equal numbers" and, frankly, if someone gets that part wrong the immediate failure combined with re-reading the word "all" should provide sufficient clarity. So I'm still for Tom and mine combined proposal with cleaning up the middle sentence even more. The other point of note is the difference between: will receive their default value and will insert the default values The system is inserting default values but the columns are receiving them. The sentence is relative to the table columns though so "receive" seems like the better fit. Minor point overall though. David J. --000000000000a9e589059a2382c8 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable <div dir=3D"ltr"><div dir=3D"ltr"><div class=3D"gmail_default" style=3D"fon= t-family:arial,helvetica,sans-serif"><span style=3D"font-family:Arial,Helve= tica,sans-serif">On Fri, Dec 20, 2019 at 7:13 AM Tom Lane <<a href=3D"ma= ilto:[email protected]">[email protected]</a>> wrote:</span><br></div></= div><div class=3D"gmail_quote"><blockquote class=3D"gmail_quote" style=3D"m= argin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left= :1ex">Bruce Momjian <<a href=3D"mailto:[email protected]" target=3D"_blan= k">[email protected]</a>> writes:<br> > OK, how is this?<br> <br> I do not like the phrasing of<br> <br> =C2=A0 =C2=A0 If a column list is<br> =C2=A0 =C2=A0 specified in <command>COPY FROM</command>, the nu= mber and position of<br> =C2=A0 =C2=A0 the columns must match those fields in the file.<br> <br> I'm not quite sure why, but that reads to me as implying that the COPY<= br> will identify columns of the file by name and match them up.=C2=A0 Or at<br= > least it could be read that way by somebody who was predisposed to<br> believe it.=C2=A0 I'd go with something more like<br> <br> =C2=A0 =C2=A0 If a column list is<br> =C2=A0 =C2=A0 specified in <command>COPY FROM</command>, only t= he listed columns<br> =C2=A0 =C2=A0 are read from the file (whose fields must match the column li= st).<br></blockquote><div><br></div><div class=3D"gmail_default" style=3D"f= ont-family:arial,helvetica,sans-serif">This has the same "match by nam= e" possibility when I read it...</div><div class=3D"gmail_default" sty= le=3D"font-family:arial,helvetica,sans-serif"><br></div><div class=3D"gmail= _default" style=3D"font-family:arial,helvetica,sans-serif">I don't see = the benefit of repeating "If a column list is specified" a second= time in the three sentence paragraph.=C2=A0 To a lesser extent the same go= es for the second repetition=C2=A0of COPY FROM.</div><div class=3D"gmail_de= fault" style=3D"font-family:arial,helvetica,sans-serif"><br></div><div clas= s=3D"gmail_default" style=3D"font-family:arial,helvetica,sans-serif">I agre= e with the general goal of trying to get rid of the parenthetical; to that = end:</div><div class=3D"gmail_default" style=3D"font-family:arial,helvetica= ,sans-serif"></div><div class=3D"gmail_default" style=3D"font-family:arial,= helvetica,sans-serif"><command>COPY FROM</command> will match a= ll listed columns in the table=C2=A0to *all* file columns by position.<br><= /div><div class=3D"gmail_default" style=3D"font-family:arial,helvetica,sans= -serif"><br></div><div class=3D"gmail_default" style=3D"font-family:arial,h= elvetica,sans-serif">That sufficiently implies the "must have equal nu= mbers" and, frankly, if someone gets that part wrong the immediate fai= lure combined with re-reading the word "all" should provide suffi= cient clarity.</div><div class=3D"gmail_default" style=3D"font-family:arial= ,helvetica,sans-serif"><br></div><div class=3D"gmail_default" style=3D"font= -family:arial,helvetica,sans-serif">So I'm still for Tom and mine combi= ned proposal with cleaning up the middle sentence even more.</div><div clas= s=3D"gmail_default" style=3D"font-family:arial,helvetica,sans-serif"><br></= div><div class=3D"gmail_default" style=3D"font-family:arial,helvetica,sans-= serif">The other point of note is the difference between:</div><div class= =3D"gmail_default" style=3D"font-family:arial,helvetica,sans-serif"><br></d= iv><div class=3D"gmail_default" style=3D"font-family:arial,helvetica,sans-s= erif">will receive their default value<br></div><div class=3D"gmail_default= " style=3D"font-family:arial,helvetica,sans-serif">and</div><div class=3D"g= mail_default" style=3D"font-family:arial,helvetica,sans-serif">will insert = the default values</div><div class=3D"gmail_default" style=3D"font-family:a= rial,helvetica,sans-serif"><br></div><div class=3D"gmail_default" style=3D"= font-family:arial,helvetica,sans-serif">The system is inserting default val= ues but the columns are receiving them.=C2=A0 The sentence is relative to t= he table columns though so "receive" seems like the better fit.= =C2=A0 Minor point overall though.</div><div class=3D"gmail_default" style= =3D"font-family:arial,helvetica,sans-serif"><br></div><div class=3D"gmail_d= efault" style=3D"font-family:arial,helvetica,sans-serif">David J.</div><div= class=3D"gmail_default" style=3D"font-family:arial,helvetica,sans-serif"><= br></div></div></div> --000000000000a9e589059a2382c8--