From: Rob Sargent <robjsargent@gmail.com>
To: Sehrope Sarkuni <sehrope@jackdb.com>
Cc: pgsql-jdbc@lists.postgresql.org
Subject: Re: PGCopyOutputStream close() v. endCopy()
Date: Fri, 11 Jan 2019 10:07:19 -0700
Message-ID: <2bc9ac77-062a-bcd5-7037-41dcc766f620@gmail.com> (raw)
In-Reply-To: <CAH7T-aqTXbXc9QEAo83ObQjzkNGEdqW_bTZj12vmA5Y8hpk5AQ@mail.gmail.com>
References: <25bf5fc6-1dd0-0944-61e7-0eae6c6614c7@gmail.com>
<CAH7T-aqTXbXc9QEAo83ObQjzkNGEdqW_bTZj12vmA5Y8hpk5AQ@mail.gmail.com>
Thanks you, very much.
I'll revert to using close() (even though the try-with will also as it
make me more comfortable).
On 1/11/19 6:36 AM, Sehrope Sarkuni wrote:
> You're getting that error because endCopy() is being called twice.
> Once by you explicitly in deliverSegments() and again when the
> PGCopyOutputStream gets automatically closed by the
> try-with-resources:
> https://github.com/pgjdbc/pgjdbc/blob/master/pgjdbc/src/main/java/org/postgresql/copy/PGCopyOutputSt...
>
> PGCopyOutputStream is a wrapper CopyIn (write to OutputStream => COPY
> TO STDIN) that adds some buffering. You shouldn't be calling endCopy()
> on it.
>
> You can either:
>
> 1. Remove the PGCopyOutputStream.endCopy() entirely as close() will
> handle it. If do not need the final row count then you're done.
> 2. Use CopyIn directly, manage the buffer yourself, and call endCopy()
> on it.
> 3. Manually manage the resources for PGCopyOutputStream so you can
> reference it for getHandledRowCount() after the close().
> 4. Call close() instead of endCopy() on PGCopyOutputStream as it
> handles being invoked more than once (it's a no-op for subsequent
> close() calls).
>
> I'm going to take a look why PGCopyOutputStream.endCopy() is declared
> public as currently there's no way to call both it and close() without
> getting an error, and you're definitely supposed to call close().
> Either it should not be public or it should be performing the same
> work as close(), i.e. clearing the internal "op" (copy operation)
> member to indicate that the close is complete so subsequent close()
> calls are not errant.
>
> Regards,
> -- Sehrope Sarkuni
> Founder & CEO | JackDB, Inc. | https://www.jackdb.com/
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-jdbc@postgresql.org
Cc: robjsargent@gmail.com, sehrope@jackdb.com
Subject: Re: PGCopyOutputStream close() v. endCopy()
In-Reply-To: <2bc9ac77-062a-bcd5-7037-41dcc766f620@gmail.com>
References: <25bf5fc6-1dd0-0944-61e7-0eae6c6614c7@gmail.com> <CAH7T-aqTXbXc9QEAo83ObQjzkNGEdqW_bTZj12vmA5Y8hpk5AQ@mail.gmail.com> <2bc9ac77-062a-bcd5-7037-41dcc766f620@gmail.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox