Skip to content

Table with transaction column name not parsed  #1477

Open

Description

@subkanthi

Describe the bug

Table with transaction column name not parsed

 create table test_execute_batch(a Int32, transaction String)engine=Memory

Expected behaviour

It should be parsed and the table should be created.

Code example

            Assert.assertFalse(stmt.execute("drop table if exists test_execute_batch; "
                    + "create table test_execute_batch(a Int32, transaction String)engine=Memory"), "Should not have result set");

Error log

2023-10-23 10:44:09:447 -0400 [main] WARN ClickHouseSqlParser - Parse error at line 1, column 83. Encountered: transaction. If you believe the SQL is valid, please feel free to open an issue on Github with this warning and the following SQL attached.
drop table if exists test_execute_batch; create table test_execute_batch(a Int32, transaction String)engine=Memory

java.sql.SQLException: Code: 62. DB::Exception: Syntax error (Multi-statements are not allowed): failed at position 40 (end of query): ; create table test_execute_batch(a Int32, transaction String)engine=Memory. . (SYNTAX_ERROR) (version 23.2.4.12 (official build))
, server ClickHouseNode [uri=http://localhost:49238/test_statement]@1568086

Configuration

Environment

  • Client version:
  • Language version:
  • OS:

ClickHouse server

  • ClickHouse Server version:
  • ClickHouse Server non-default settings, if any:
  • CREATE TABLE statements for tables involved:
  • Sample data for all these tables, use clickhouse-obfuscator if necessary

Activity

  1. mzitnik commented on Oct 25, 2023

    @mzitnik
    Contributor

    @subkanthi Can you provide a simple snippet that reproduces the issue?

  2. subkanthi commented on Oct 25, 2023

    @subkanthi
    ContributorAuthor

    Hi @mzitnik , here is the modified Integration test

        @Test(groups = "integration")
        public void testExecuteBatch() throws SQLException {
            Properties props = new Properties();
            try (Connection conn = newConnection(props); Statement stmt = conn.createStatement()) {
                Assert.assertEquals(stmt.executeBatch(), new int[0]);
                Assert.assertEquals(stmt.executeLargeBatch(), new long[0]);
                stmt.addBatch("select 1");
                stmt.clearBatch();
                Assert.assertEquals(stmt.executeBatch(), new int[0]);
                Assert.assertEquals(stmt.executeLargeBatch(), new long[0]);
                stmt.addBatch("select 1");
                // mixed usage
                Assert.assertThrows(SQLException.class, () -> stmt.execute("select 2"));
                Assert.assertThrows(SQLException.class, () -> stmt.executeQuery("select 2"));
                Assert.assertThrows(SQLException.class,
                        () -> stmt.executeLargeUpdate("drop table if exists non_existing_table"));
                Assert.assertThrows(SQLException.class,
                        () -> stmt.executeUpdate("drop table if exists non_existing_table"));
                // query in batch
                Assert.assertThrows(BatchUpdateException.class, () -> stmt.executeBatch());
                stmt.addBatch("select 1");
                Assert.assertThrows(BatchUpdateException.class, () -> stmt.executeLargeBatch());
    
                Assert.assertFalse(stmt.execute("drop table if exists test_execute_batch; "
                        + "create table test_execute_batch(a Int32, transaction String)engine=Memory"), "Should not have result set");
                stmt.addBatch("insert into test_execute_batch values(1,'1')");
                stmt.addBatch("insert into test_execute_batch values(2,'2')");
                stmt.addBatch("insert into test_execute_batch values(3,'3')");
                Assert.assertEquals(stmt.executeBatch(), new int[] { 1, 1, 1 });
    

    Note: with backticks it works transaction

  3. added
    legacy
    on Jun 18, 2024
  4. mva-coinify commented on Nov 1, 2024

    @mva-coinify

    Any chance this can be fixed? Seems like the issue is replicable and has been a year ago.

  5. chernser commented on Nov 4, 2024

    @chernser
    Contributor

    Good day, @mva-coinify!
    Will look into it.
    Would it help if column is wrapped with "?

  6. added this to the Priority Backlog milestone on Nov 4, 2024
  7. added
    jdbc
    on Jan 9, 2025
  8. chernser commented on Jan 9, 2025

    @chernser
    Contributor

    need to retest with new jdbc driver

  9. removed this from the Priority Backlog milestone on Jan 10, 2025
  10. github-actions commented on Jan 11, 2026

    @github-actions

    This issue has been automatically marked as stale because it has not had activity in the last year. It will be closed in 30 days if no further activity occurs. Please feel free to leave a comment if you believe the issue is still relevant. Thank you for your contributions!

  11. chernser commented on Jan 30, 2026

    @chernser
    Contributor

    parser problem. know issue.

  12. added this to the 0.12.0 milestone on Jul 22, 2026
  13. removed this from the 0.12.0 milestone on Nov 10, 2026
  14. added
    queries
    and removed
    legacy
    on Nov 26, 2026
  15. polyglotAI-bot commented on Nov 28, 2026

    @polyglotAI-bot
    Collaborator

    Recommendation: Keep open — fix needed
    Only the v1 driver (clickhouse.jdbc.v1=true) still fails to parse transaction as a column name. jdbc-v2, the default driver of the clickhouse-jdbc artifact, parses it since #2725 (first release v0.9.7), so the fix is needed in v1 only.

    Analysis: In the v1 grammar, the rule anyKeyword (the keywords that can be names) has no <TRANSACTION> (clickhouse-jdbc/src/main/javacc/ClickHouseSqlParser.jj:1010). So the v1 parser stops at the column name: a single statement still runs, but the driver cannot split two statements, and it sends them to the server as one. The jdbc-v2 grammar has <TRANSACTION> in the same rule (jdbc-v2/src/main/javacc/ClickHouseSqlParser.jj:1093); jdbc-v2 does not accept two statements in one execute call (jdbc-v2/src/main/java/com/clickhouse/jdbc/internal/SqlParserFacade.java:236).

    Reproduction: complete program and output

    Changed from the issue's steps: the TestNG test is a main that runs with jdbc-v2 and with the v1 driver (compress=0 because of #3107); added a contrast with a column b, the statements one by one, and a prepared insert.

    import java.sql.Connection;
    import java.sql.DriverManager;
    import java.sql.PreparedStatement;
    import java.sql.Statement;
    import java.util.Arrays;
    import java.util.Properties;
    
    public class Repro {
        static final String URL = System.getenv().getOrDefault("CLICKHOUSE_URL", "http://localhost:8123");
        static final String PASSWORD = System.getenv().getOrDefault("CLICKHOUSE_PASSWORD", "");
    
        public static void main(String[] args) throws Exception {
            // jdbc-v2 (default driver of the clickhouse-jdbc artifact)
            run("jdbc-v2", "");
            // v1 driver; compress=0 avoids clickhouse-java#3107 on server 26.9+
            run("jdbc-v1", "?clickhouse.jdbc.v1=true&compress=0");
        }
    
        static void run(String label, String urlSuffix) throws Exception {
            Properties props = new Properties();
            props.setProperty("user", "default");
            props.setProperty("password", PASSWORD);
            String jdbcUrl = "jdbc:clickhouse:" + URL.replaceFirst("^https?:", "") + "/default" + urlSuffix;
            try (Connection conn = DriverManager.getConnection(jdbcUrl, props); Statement stmt = conn.createStatement()) {
                System.out.println(label + ": connection class " + conn.getClass().getName());
                // The issue's statement: two statements in one execute() call
                try {
                    boolean rs = stmt.execute("drop table if exists test_execute_batch; "
                            + "create table test_execute_batch(a Int32, transaction String)engine=Memory");
                    System.out.println(label + " multi-statement: execute returned " + rs);
                } catch (Exception e) {
                    System.out.println(label + " multi-statement: " + e.getClass().getName() + ": " + firstLine(e.getMessage()));
                }
                // Contrast: the same two statements with the column named b
                try {
                    boolean rs = stmt.execute("drop table if exists test_execute_batch_b; "
                            + "create table test_execute_batch_b(a Int32, b String)engine=Memory");
                    System.out.println(label + " multi-statement, column b: execute returned " + rs);
                    stmt.execute("drop table if exists test_execute_batch_b");
                } catch (Exception e) {
                    System.out.println(label + " multi-statement, column b: " + e.getClass().getName() + ": " + firstLine(e.getMessage()));
                }
                // The same statements, one per execute() call
                try {
                    stmt.execute("drop table if exists test_execute_batch");
                    boolean rs = stmt.execute("create table test_execute_batch(a Int32, transaction String)engine=Memory");
                    System.out.println(label + " single create: execute returned " + rs);
                } catch (Exception e) {
                    System.out.println(label + " single create: " + e.getClass().getName() + ": " + firstLine(e.getMessage()));
                }
                // The issue's batch inserts
                try {
                    stmt.addBatch("insert into test_execute_batch values(1,'1')");
                    stmt.addBatch("insert into test_execute_batch values(2,'2')");
                    stmt.addBatch("insert into test_execute_batch values(3,'3')");
                    System.out.println(label + " executeBatch: " + Arrays.toString(stmt.executeBatch()));
                } catch (Exception e) {
                    System.out.println(label + " executeBatch: " + e.getClass().getName() + ": " + firstLine(e.getMessage()));
                }
                // A prepared insert that names the column
                try (PreparedStatement ps = conn.prepareStatement("insert into test_execute_batch(a, transaction) values(?, ?)")) {
                    ps.setInt(1, 4);
                    ps.setString(2, "4");
                    ps.addBatch();
                    System.out.println(label + " prepared insert: " + Arrays.toString(ps.executeBatch()));
                } catch (Exception e) {
                    System.out.println(label + " prepared insert: " + e.getClass().getName() + ": " + firstLine(e.getMessage()));
                }
                stmt.execute("drop table if exists test_execute_batch");
            }
        }
    
        static String firstLine(String s) {
            if (s == null) return "null";
            int i = s.indexOf('\n');
            return i < 0 ? s : s.substring(0, i);
        }
    }

    Output on main (8480ca001), ClickHouse 26.11.4.11:

    jdbc-v2 multi-statement: java.lang.RuntimeException: More than one SQL statement found: drop table if exists test_execute_batch; …
    jdbc-v2 multi-statement, column b: java.lang.RuntimeException: More than one SQL statement found: …
    jdbc-v2 single create: execute returned false
    jdbc-v2 executeBatch: [1, 1, 1]
    jdbc-v2 prepared insert: [1]
    [main] WARN ClickHouseSqlParser - Parse error at line 1, column 83.  Encountered: transaction. …
    jdbc-v1 multi-statement: java.sql.SQLException: Code: 62. DB::Exception: Syntax error (Multi-statements are not allowed): …
    jdbc-v1 multi-statement, column b: execute returned false
    [main] WARN ClickHouseSqlParser - Parse error at line 1, column 42.  Encountered: transaction. … (the same for the INSERT)
    jdbc-v1 single create: execute returned false
    jdbc-v1 executeBatch: [1, 1, 1]
    jdbc-v1 prepared insert: [1]
    

    Automated triage by Polyglot AI. A maintainer makes the final decision.

  16. added
    legacy
    sql-parser
    on Nov 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugjdbclegacyqueriessql-parser

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions