Skip to content

Add copy examples#2762

Merged
davecramer merged 3 commits intopgjdbc:masterfrom
davecramer:doc-copyapi
Feb 9, 2023
Merged

Add copy examples#2762
davecramer merged 3 commits intopgjdbc:masterfrom
davecramer:doc-copyapi

Conversation

@davecramer
Copy link
Copy Markdown
Member

No description provided.

Comment on lines +954 to +955
} catch (Exception ex) {
ex.printStackTrace();
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess this catch is non-essential, and we don't want to promote printStackTrace pattern :)

Suggested change
} catch (Exception ex) {
ex.printStackTrace();

Comment on lines +947 to +950
try {
cp.cancelCopy();
} catch (SQLException se) { // should fail with obsolete operation
se.printStackTrace();
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we require calling cancelCopy? Why call it if we expect it to fail?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I pulled this out of a test case. We really don't need it.

private int dataRows = origData.length;
private String sql = "COPY copytest FROM STDIN";
try (Connection con = DriverManager.getConnection(url, "postgres", "somepassword")){
createTempTable(con, "copytest", "stringvalue text, intvalue int, numvalue numeric(5,2)");
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ideally, the sample should be copy-pasteable, so we should use plain try (Statement st = con.createStatement()) { st.execute("create table ...") }

An alternative option is to provide table DDL above Java code, so the users create or reuse an existing table.

CopyOut cp = copyAPI.copyOut(sql);
int count = 0;
byte[] buf;
while ((buf = cp.readFromCopy()) != null) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be nice to clarify what does byte[] buf mean.
Does it contain single row only? Does it contain just a bunch of next bytes?

Comment thread docs/content/documentation/server-prepare.md Outdated
@davecramer davecramer merged commit d221b6b into pgjdbc:master Feb 9, 2023
davecramer added a commit to davecramer/pgjdbc that referenced this pull request Feb 14, 2023
* Add copy examples
davecramer added a commit that referenced this pull request Feb 15, 2023
* fix: fix testGetSQLTypeQueryCache by searching for xid type. We used to search for box type but it is now cached
fix OidValueCorrectnessTest BOX_ARRAY OID, by adding BOX_ARRAY to the oidTypeName map

* branches: '*' to branches: '**' in the workflow definition
to ensure that all pull requests get tested

* added alias /about/license.html (#2765)

* Add copy examples (#2762)

* make changelogs more compact, only show the link to the changelog (#2758)

add SNAPSHOT link to download page

* Update README.md (#2759)

* re-add slonik duke image (#2760)

* edit changelogs to make them correct and readable (#2743)

* Correct the instructions for building without tests
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants