Thread: Re: [BUGS] BUG #6083: psql script line numbers incorrectly count \copy data

"Steve Haslam" <araqnid@googlemail.com> writes:
> ... Apparently, the data read from \copy
> is incrementing the script line number counter?

Yeah, so it is.  That is correct behavior for COPY FROM STDIN,
but not so much for copying from a separate file.

The attached patch seems like an appropriate fix.  However, I'm unsure
whether to apply it to released branches ... does anyone think this
might break somebody's application?

            regards, tom lane

diff --git a/src/bin/psql/copy.c b/src/bin/psql/copy.c
index 5e69d29b6cbeab56aa0c85e85c3edce46d06efac..ebe5ee9ea551b858a4ad6119322405109d3212d8 100644
*** a/src/bin/psql/copy.c
--- b/src/bin/psql/copy.c
*************** handleCopyIn(PGconn *conn, FILE *copystr
*** 586,592 ****
                  }
              }

!             pset.lineno++;
          }
      }

--- 586,593 ----
                  }
              }

!             if (copystream == pset.cur_cmd_source)
!                 pset.lineno++;
          }
      }


Re: [BUGS] BUG #6083: psql script line numbers incorrectly count \copy data

From
David Fetter
Date:
On Mon, Jul 04, 2011 at 12:02:12PM -0400, Tom Lane wrote:
> "Steve Haslam" <araqnid@googlemail.com> writes:
> > ... Apparently, the data read from \copy is incrementing the
> > script line number counter?
> 
> Yeah, so it is.  That is correct behavior for COPY FROM STDIN, but
> not so much for copying from a separate file.
> 
> The attached patch seems like an appropriate fix.  However, I'm
> unsure whether to apply it to released branches ... does anyone
> think this might break somebody's application?

No.

Cheers,
David.
-- 
David Fetter <david@fetter.org> http://fetter.org/
Phone: +1 415 235 3778  AIM: dfetter666  Yahoo!: dfetter
Skype: davidfetter      XMPP: david.fetter@gmail.com
iCal: webcal://www.tripit.com/feed/ical/people/david74/tripit.ics

Remember to vote!
Consider donating to Postgres: http://www.postgresql.org/about/donate


On Mon, Jul 4, 2011 at 12:02 PM, Tom Lane <tgl@sss.pgh.pa.us> wrote:
> "Steve Haslam" <araqnid@googlemail.com> writes:
>> ... Apparently, the data read from \copy
>> is incrementing the script line number counter?
>
> Yeah, so it is.  That is correct behavior for COPY FROM STDIN,
> but not so much for copying from a separate file.
>
> The attached patch seems like an appropriate fix.  However, I'm unsure
> whether to apply it to released branches ... does anyone think this
> might break somebody's application?

I think this is pretty safe.

--
Robert Haas
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company