• Tom Lane's avatar
    Fix tracking of psql script line numbers during \copy from another place. · e85a5ffb
    Tom Lane authored
    Commit 08146775 changed do_copy() to
    temporarily scribble on pset.cur_cmd_source.  That was a mighty ugly bit of
    code in any case, but in particular it broke handleCopyIn's ability to tell
    whether it was reading from the current script source file (in which case
    pset.lineno should be incremented for each line of COPY data), or from
    someplace else (in which case it shouldn't).  The former case still worked,
    the latter not so much.  The visible effect was that line numbers reported
    for errors in a script file would be wrong if there were an earlier \copy
    that was reading anything other than inline-in-the-script-file data.
    
    To fix, introduce another pset field that holds the file do_copy wants the
    COPY code to use.  This is a little bit ugly, but less so than passing the
    file down explicitly through several layers that aren't COPY-specific.
    
    Extracted from a larger patch by Kumar Rajeev Rastogi; that patch also
    changes printing of COPY command tags, which is not a bug fix and shouldn't
    get back-patched.  This particular idea was from a suggestion by Amit
    Khandekar, if I'm reading the thread correctly.
    
    Back-patch to 9.2 where the faulty code was introduced.
    e85a5ffb
common.c 38.2 KB