Confusing COPY support documentation

"Ben Tilly" <[email protected]>
Newsgroups gmane.comp.db.postgresql.dbdpg
Message-ID <[email protected]>
I just spent an hour banging my head against the wall before I figured
out two annoying things about the COPY support in DBD::Pg.

1. In the call to pg_getline, do NOT pass in an undefined variable in.
 You will get warnings.  So instead of something like:

  while ($dbd->pg_getline(my $line, $size)) {
    # do stuff
  }

write

  my $line = "";
  while ($dbd->pg_getline($line, $size)) {
    # do stuff
  }

(I would complain about the $size part, but googling on the topic
suggests that a future release will remove that parameter, and take
care of the related potential for buffer overflows.)

2. You don't want to call pg_endcopy on a handle that you are using
pg_getline with.  Because pg_getline will do and end copy for you on
your last line.  Which means that your call to pg_endcopy will blow up
in a most annoying fashion.

Cheers,
Ben
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.