Re: COPY table FROM STDIN doesn't show count tag - Mailing list pgsql-hackers

From Rajeev rastogi
Subject Re: COPY table FROM STDIN doesn't show count tag
Date
Msg-id BF2827DCCE55594C8D7A8F7FFD3AB7713DDAC5A5@SZXEML508-MBX.china.huawei.com
Whole thread Raw
In response to COPY table FROM STDIN doesn't show count tag  (Rajeev rastogi <rajeev.rastogi@huawei.com>)
List pgsql-hackers
<div class="WordSection1"><p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto">On 20
November,Amit Khandekar wrote:<p class="MsoNormal"
style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto">>>>>Ihope you meant to write test case as
<b>psql-d postgres -c "\copy tab from <span style="color:red">stdin</span>; insert into tab values ('lll', 3)", </b>as
ifwe are reading from file, then the above issue does not come.<p class="MsoNormal"
style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto">>>>Imeant COPY with a slash. \COPY is equivalent to
COPYFROM STDIN. So the issue can also be reproduced by :<p class="MsoNormal"
style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto">>>>\COPYtab from 'client_filename' ...<p
class="MsoNormal"style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto">  <p class="MsoNormal"
style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"> >>>>Ihave modified the patch as per your
commentand same is attached with this mail.<p class="MsoNormal"
style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"> <pclass="MsoNormal"
style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto">>>>Thanks.The COPY FROM looks good.<p
class="MsoNormal"style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto">>>OK..Thanks <p class="MsoNormal"
style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto">>>>Withthe patch applied, \COPY TO 'data_file'
commandoutputs the  COPY status into the data file, instead of printing it in the psql session.<p class="MsoNormal"
style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto">>>>postgres=#\copy tab to '/tmp/fout';<p
class="MsoNormal"style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto">>>>postgres=# <p class="MsoNormal"
style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"> >>>$cat /tmp/fout <p class="MsoNormal"
style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto">>>>ee     909<p class="MsoNormal"
style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto">>>>COPY1<p class="MsoNormal"
style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto">>>>Thisis probably because client-side COPY
overridesthe pset.queryFout with its own destination file, and while printing the COPY status, the overridden file
pointeris not yet reverted back.<p class="MsoNormal"
style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"> >><span
style="font-size:11.0pt;font-family:"Calibri","sans-serif"">Thislooks to be an issue without our new patch also. Like I
triedfollowing command and output was as follows:</span><p class="MsoNormal"
style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto;margin-left:36.0pt">>><span
style="font-size:11.0pt;font-family:"Calibri","sans-serif""><a
href="mailto:rajeev@linux-ltr9:~/9.4gitcode/install/bin">rajeev@linux-ltr9:~/9.4gitcode/install/bin</a>>./psql -d
postgres-c "\copy tbl to 'new.txt';insert into tbl values(55);"</span><p class="MsoNormal"
style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto;margin-left:36.0pt">>><span
style="font-size:11.0pt;font-family:"Calibri","sans-serif""><a
href="mailto:rajeev@linux-ltr9:~/9.4gitcode/install/bin">rajeev@linux-ltr9:~/9.4gitcode/install/bin</a>>cat
new.txt</span><pclass="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto;margin-left:36.0pt">
>><spanstyle="font-size:11.0pt;font-family:"Calibri","sans-serif"">5</span><p class="MsoNormal"
style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto;margin-left:36.0pt">>><span
style="font-size:11.0pt;font-family:"Calibri","sans-serif"">67</span><pclass="MsoNormal"
style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto;margin-left:36.0pt">>><span
style="font-size:11.0pt;font-family:"Calibri","sans-serif"">5</span><pclass="MsoNormal"
style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto;margin-left:36.0pt">>><span
style="font-size:11.0pt;font-family:"Calibri","sans-serif"">67</span><pclass="MsoNormal"
style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto;margin-left:36.0pt">>><span
style="font-size:11.0pt;font-family:"Calibri","sans-serif"">2</span><pclass="MsoNormal"
style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto;margin-left:36.0pt">>><span
style="font-size:11.0pt;font-family:"Calibri","sans-serif"">2</span><pclass="MsoNormal"
style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto;margin-left:36.0pt">>><span
style="font-size:11.0pt;font-family:"Calibri","sans-serif"">99</span><pclass="MsoNormal"
style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto;margin-left:36.0pt">>><span
style="font-size:11.0pt;font-family:"Calibri","sans-serif"">1</span><pclass="MsoNormal"
style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto;margin-left:36.0pt">>><span
style="font-size:11.0pt;font-family:"Calibri","sans-serif"">1</span><pclass="MsoNormal"
style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto;margin-left:36.0pt">><span
style="font-size:11.0pt;font-family:"Calibri","sans-serif"">INSERT0 1</span><p class="MsoNormal"> <p
class="MsoNormal">>Ok.Yes it is an existing issue. Because we are now printing the COPY status even for COPY TO, the
existingissue surfaces too easily with the patch. \COPY TO is a pretty common scenario. And it does not have to have a
subsequentanother command <p class="MsoNormal">>to reproduce the issue Just a single \COPY TO command reproduces the
issue.<pclass="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto">>><span
style="font-size:11.0pt;font-family:"Calibri","sans-serif"">Ihave fixed the same as per your suggestion by resetting
thepset.queryFout after the function call “handleCopyOut”.</span><p class="MsoNormal">>>!
                                        pset.queryFout = stdout;<p class="MsoNormal"> <p class="MsoNormal">>The
originalpset.queryFout may not be stdout. psql -o option can override the stdout default.<p class="MsoNormal"> <p
class="MsoNormal">>Ithink solving the \COPY TO part is going to be a  different (and an involved) issue to solve
thanthe COPY FROM. Even if we manage to revert back the queryFout, I think ProcessResult() is not the right place to do
it.ProcessResult() should not <p class="MsoNormal">> assume that  somebody else has changed queryFout. Whoever has
changedit should revert it. Currently, do_copy() is indeed doing this correctly:<p class="MsoNormal"> <p
class="MsoNormal">>         save_file = *override_file;<p class="MsoNormal">>          *override_file =
copystream;<pclass="MsoNormal">>          success = SendQuery(query.data);<p class="MsoNormal">>         
*override_file= save_file;<p class="MsoNormal"> <p class="MsoNormal">>But the way SendQuery() itself processes the
resultsand prints them, is conflicting with the above. <p class="MsoNormal"> <p class="MsoNormal">>So I think it is
bestto solve this as a different issue, and we should , for this commitfest,  fix only COPY FROM. Once the \COPY
existingissue is solved, only then we can start printing the \COPY TO status as well.<p class="MsoNormal"> <p
class="MsoNormal">Youmean to say that I should change the patch to keep only COPY FROM related changes and remove
changesrelated to COPY TO. <p class="MsoNormal">If yes, then I shall change the patch accordingly  and also mention
samein documentation also.<p class="MsoNormal">Please let me know about this so that I can share the modified patch.<p
class="MsoNormal"> <pclass="MsoNormal">Thanks and Regards,<p class="MsoNormal">Kumar Rajeev Rastogi</div> 

pgsql-hackers by date:

Previous
From: Rajeev rastogi
Date:
Subject: Re: Add min and max execute statement time in pg_stat_statement
Next
From: Bruce Momjian
Date:
Subject: Re: [GENERAL] pg_upgrade ?deficiency