in reply to Re^2: pg_getcopydata failing to get copy data using documented syntax
in thread pg_getcopydata failing to get copy data using documented syntax

$dbh->pg_getcopydata(\$data[$record_count++])
This is a post-increment.

When the last data record is retrieved, pg_getcopydata returns a Non-zero value, so, it is called one more time, and this time it returns NO data, but the return code is negative.

So, that last call with no data increments the $record_count unnecessarily.

Any attempt to repair this in-line loses the simplicity of the current code, so the best bet is to add a line "$record_count --", and add a comment as to why you are doing that.

Re- Quoting the $schema, $table: Ouch! spaces in these names is just poor DB design. I agree with you - adding the quotes is good practice, just for these cases (which I had not thought of).

            "Battle not with trolls, lest ye become a troll; and if you gaze into the Internet, the Internet gazes also into you."
        -Friedrich Nietzsche: A Dynamic Translation

  • Comment on Re^3: pg_getcopydata failing to get copy data using documented syntax
  • Download Code

Replies are listed 'Best First'.
Re^4: pg_getcopydata failing to get copy data using documented syntax
by bitvector (Initiate) on Dec 28, 2011 at 21:16 UTC

    Makes sense. Thanks for the clarification. I suppose using pop(@data) is about as good as $record_count-- before the pg_getcopydata() line - unless you have a suggestion to the contrary...

    The original database was migrated from an Access app. One of my key projects here is to get it migrated to something with sane schema. Until then, there're all sorts of hoops like the quoting I have to jump through...

    Thanks again!