Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Postgres JDBC driver cursor mode #806

Closed
ideoma opened this issue Feb 11, 2021 · 1 comment
Closed

Postgres JDBC driver cursor mode #806

ideoma opened this issue Feb 11, 2021 · 1 comment
Labels
New feature Feature requests Postgres Wire Issues or changes relating to Postres wire protocol

Comments

@ideoma
Copy link
Collaborator

ideoma commented Feb 11, 2021

Is your feature request related to a problem? Please describe.
As per JDBC driver docs it can execute select queries in Cursor Mode (rather than fetching all rows in the default mode) when

  • The Connection must not be in auto-commit mode.
  • Statement setFetchSize is set.

Here is test code to try with QuestDb, can be pasted to core/src/main/java/io/questdb/cutlass/pgwire/PGConnectionContext.java

    @Test
    public void testCursorFetch() throws Exception {
        assertMemoryLeak(() -> {
            try (
                    final PGWireServer ignored = createPGServer(1);
                    final Connection connection = getConnection(false, true)
            ) {
                connection.setAutoCommit(false);
                int totalRows = 1000000;
                CallableStatement stmt = connection.prepareCall(
                        "create table x as (select" +
                                " cast(x as int) kk, " +
                                " rnd_int() a," +
                                " rnd_boolean() b," + // str
                                " rnd_str(1,1,2) c," + // str
                                " rnd_double(2) d," +
                                " rnd_float(2) e," +
                                " rnd_short(10,1024) f," +
                                " rnd_date(to_date('2015', 'yyyy'), to_date('2016', 'yyyy'), 2) g," +
                                " rnd_symbol(4,4,4,2) i," + // str
                                " rnd_long() j," +
                                " timestamp_sequence(889001, 8890012) k," +
                                " rnd_byte(2,50) l," +
                                " rnd_bin(10, 20, 2) m," +
                                " rnd_str(5,16,2) n," +
                                " rnd_char() cc," + // str
                                " rnd_long256() l2" + // str
                                " from long_sequence("+ totalRows +"))" // str
                );
                stmt.execute();

                try (PreparedStatement statement = connection.prepareStatement("x")) {
                    statement.setFetchSize(10);
                    int count = 0;
                    try (ResultSet rs = statement.executeQuery()) {
                        rs.getInt(1);
                        count++;
                    }
                    Assert.assertEquals(totalRows, count);
                }
            }
        });
    }

The test fails with QuestDb disconnecting while executing the SELECT with error

PGConnectionContext statement does not exist [name=C_1]

Describe the solution you'd like
Postgress JDBC Driver cursor fetch

Describe alternatives you've considered
Multiple queries with LIMIT ,

Additional context
No

@ideoma ideoma added the New feature Feature requests label Feb 11, 2021
@bluestreak01 bluestreak01 added the Postgres Wire Issues or changes relating to Postres wire protocol label Feb 17, 2021
@ghost ghost self-assigned this Mar 3, 2021
@ghost ghost removed their assignment Mar 11, 2021
@ghost ghost linked a pull request Mar 14, 2021 that will close this issue
eugenels added a commit to eugenels/questdb that referenced this issue May 13, 2021
@msis
Copy link

msis commented Oct 20, 2021

I'm having an error when using cursor mode in C++:

ERROR:  unexpected token: SCROLL
LINE 1: DECLARE "stream_1" SCROLL CURSOR FOR SELECT timestamp, msg_...

Is it related to this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
New feature Feature requests Postgres Wire Issues or changes relating to Postres wire protocol
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants