Skip to content

[jdbc-v2] [output format] SQL Error [HY000]: Only RowBinaryWithNameAndTypes is supported for output format. Please check your query. #2715

Description

@ikfid

Description

Migrating from clickhouse jdbc driver 0.6.5 to clickhouse jdbc v2 driver 0.9.6, some queries stopped working.

Steps to reproduce

  1. SELECT 1 as x FORMAT JSON

Error Log or Exception StackTrace

Exception in thread "main" java.sql.SQLException: Only RowBinaryWithNameAndTypes is supported for output format. Please check your query.
	at com.clickhouse.jdbc.StatementImpl.executeQueryImpl(StatementImpl.java:164)
	at com.clickhouse.jdbc.PreparedStatementImpl.executeQuery(PreparedStatementImpl.java:144)
	at ClickHouseTest.main(ClickHouseTest.java:18)

Clickhouse server does not produce any error, and 'clickhouse client' executes the above query without issues, therefore, I assume, there is some issue at the jdbc client side.

Expected output

{                     
 "meta":              
 [                    
  {                   
   "name": "x",       
   "type": "UInt8"    
  }                   
 ],                   
                      
 "data":              
 [                    
  {                   
   "x": 1             
  }                   
 ],                   
                      
 "rows": 1,           
                      
 "statistics":        
 {                    
  "elapsed": 0.001607,
  "rows_read": 1,     
  "bytes_read": 1     
 }                    
}                     

Sample code

implementation "com.clickhouse:clickhouse-jdbc-all:0.9.6"

import javax.sql.DataSource;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.Properties;

public class ClickHouseTest {

    public static void main(String[] args) throws Exception {
        Properties properties = new Properties();
        properties.setProperty("user", "default");
        properties.setProperty("password", "");

        DataSource dataSource = new com.clickhouse.jdbc.DataSourceImpl("jdbc:clickhouse://127.0.0.1:8123", properties);
        Connection connection = dataSource.getConnection();
        PreparedStatement stmt = connection.prepareStatement("SELECT 1 as x FORMAT JSON");
        ResultSet rs = stmt.executeQuery();
        while (rs.next()) {
            String json = rs.getString(1);
            System.out.println(json);
        }
        stmt.close();
        connection.close();
    }
}

Environment

  • Cloud
  • Client version: 0.9.6
  • Language version: 21
  • OS:

ClickHouse Server

  • ClickHouse Server version: 26.1.1.399
  • ClickHouse Server non-default settings, if any:

Activity

  1. chernser commented on Jul 16, 2026

    @chernser
    Contributor

    @ikfid

    Thank you for reporting the issue!

    We have not ported this "feature" because wanted to make V2 following standard. In this particular case we also need to support JSON format because it is not just JSON but data + metadata. Metadata should be parsed into ResultSetMetadata to keep JDBC driver usable.
    In 0.10.0-rc1 we have added support for JSONEachRow in the way you can plugin your favorite JSON library and get already parsed data. https://github.com/ClickHouse/clickhouse-java/tree/main/examples/jdbc-v2-json-processors
    Would it work in your case?

    This code will work only with ClickHouse driver. Would it more convenient if we add a shortcut method to make request with internal client?

    Sorry for breaking the compatibility but we have to handle many use-cases.

    Thanks!

  2. ikfid commented on Jul 17, 2026

    @ikfid
    Author

    @chernser , thanks for providing your feedback for this issue.

    I've checked again the use case I had in mind and, to be honest, cannot recall the exact details.
    The production code is relying on JSONEachRow since 2025, while I opened the ticket in 2026.

    Therefore, I think, I reported this ticket because of another use case - querying data via DBeaver.
    Imagine, I have clickhouse client and DBeaver client. In both I wanted to execute the same query with FORMAT JSON output.
    but it worked fine in clickhouse client and stopped working in DBeaver (relying on JDBC drivers). I guess, that was the case.
    Also, I can recall explain plain <sql> in DBeaver failed with exact same exception. Maybe this also triggered me to report this ticket. I just don't remember how far I went in root cause analysis 😄.

    Having said that - I certainly can fix my code (it's already fixed), but cannot make something get to work in DBeaver that used to work there, and hard to explain why it continues working in clickhouse client and not in DBeaver.

  3. telperions commented on Jul 17, 2026

    @telperions

    There also will be nice to have a support for FORMAT Null for query speed evaluation, since it just executes query and not returns any data to client. It was supported back in 0.6.3. And now we can not use it in Datagrip/DBeaver

  4. chernser commented on Jul 28, 2026

    @chernser
    Contributor

    @telperions added as another issue #2963

    @ikfid I will see what we can do here.

  5. added this to the 0.12.0 milestone on Jul 28, 2026
  6. added
    data-types
    on Jul 28, 2026
  7. removed this from the 0.12.0 milestone on Oct 14, 2026
  8. polyglotAI-bot commented on Nov 28, 2026

    @polyglotAI-bot
    Collaborator

    Recommendation: Keep open — maintainer decision
    Decide whether jdbc-v2 gives FORMAT JSON output through a ResultSet. The getClient() workaround that #2927 documented also needs a docs change for ClickHouse 26.8+ (Analysis).

    • Category: Feature
    • Classification: impact: none · area: Data types & formats (JSON format)
    • Status on main: Not supported on main — on ClickHouse 26.3 the issue's code throws the reported SQLException; on 26.11 it returns column x = 1 with no error.
    • Breaking change: No — can be done without a break, behind a new option.
    • Duplicates / related: Same root cause as Regression on format JSONEachRow with JDBC v2 #2799 (JSONEachRow as text): one decision covers both.
    • Workaround: getClient().query("SELECT 1 AS x", new QuerySettings().setFormat(ClickHouseFormat.JSON)) returns the JSON document on both servers.

    Analysis: jdbc-v2 reads only RowBinaryWithNamesAndTypes and parsed JSONEachRow, and rejects other formats (jdbc-v2/src/main/java/com/clickhouse/jdbc/StatementImpl.java:329); docs/features.md:123 documents that FORMAT JSON is not a ResultSet. On ClickHouse 26.8+ the default format header of the driver replaces the FORMAT clause (docs/integration-jdbc.md:501), so the clause has no effect. Docs change: the getClient().query("SELECT 1 AS x FORMAT JSON") example (docs/client-v2-json-support.md:374, docs/features.md:123) gets RowBinaryWithNamesAndTypes bytes on 26.8+, not JSON. EXPLAIN PLAN, which the reporter also recalls, works on both servers.

    Reproduction: complete program and output

    Changed from the issue's steps: the URL and password come from the environment, each case catches its exception, and the EXPLAIN PLAN and getClient() cases are added.

    import com.clickhouse.client.api.query.QueryResponse;
    import com.clickhouse.client.api.query.QuerySettings;
    import com.clickhouse.data.ClickHouseFormat;
    import com.clickhouse.jdbc.ConnectionImpl;
    import java.io.ByteArrayOutputStream;
    import java.io.InputStream;
    import java.sql.Connection;
    import java.sql.PreparedStatement;
    import java.sql.ResultSet;
    import java.util.Properties;
    import javax.sql.DataSource;
    
    public class Repro {
        static final String URL = System.getenv().getOrDefault("CLICKHOUSE_URL", "http://localhost:8123");
        static final String PASSWORD = System.getenv().getOrDefault("CLICKHOUSE_PASSWORD", "");
    
        static void jdbc(Connection connection, String sql) {
            try (PreparedStatement stmt = connection.prepareStatement(sql); ResultSet rs = stmt.executeQuery()) {
                StringBuilder rows = new StringBuilder();
                while (rs.next()) {
                    rows.append(rs.getString(1)).append(" | ");
                }
                System.out.println(sql + " -> column " + rs.getMetaData().getColumnName(1) + ": " + rows);
            } catch (Exception e) {
                System.out.println(sql + " -> " + e.getClass().getName() + ": " + e.getMessage());
            }
        }
    
        static void client(Connection connection, String label, String sql, QuerySettings settings) {
            try (QueryResponse response = connection.unwrap(ConnectionImpl.class).getClient().query(sql, settings).get()) {
                ByteArrayOutputStream out = new ByteArrayOutputStream();
                InputStream in = response.getInputStream();
                byte[] buf = new byte[4096];
                for (int n; (n = in.read(buf)) > 0; ) out.write(buf, 0, n);
                String text = new String(out.toByteArray(), "UTF-8").replaceAll("\\s+", " ").replaceAll("\\p{Cntrl}", ".");
                System.out.println(label + " -> format " + response.getFormat() + ": " + text.substring(0, Math.min(text.length(), 30)));
            } catch (Exception e) {
                System.out.println(label + " -> " + e.getClass().getName() + ": " + e.getMessage());
            }
        }
    
        public static void main(String[] args) throws Exception {
            Properties properties = new Properties();
            properties.setProperty("user", "default");
            properties.setProperty("password", PASSWORD);
    
            DataSource dataSource = new com.clickhouse.jdbc.DataSourceImpl("jdbc:clickhouse:" + URL.replaceFirst("^https?:", ""), properties);
            try (Connection connection = dataSource.getConnection()) {
                jdbc(connection, "SELECT 1 as x FORMAT JSON");   // the issue's query
                jdbc(connection, "EXPLAIN PLAN SELECT 1");
                // docs/client-v2-json-support.md: FORMAT clause through the client of the connection
                client(connection, "getClient() + FORMAT JSON", "SELECT 1 AS x FORMAT JSON", new QuerySettings());
                // the format in the settings
                client(connection, "getClient() + setFormat(JSON)", "SELECT 1 AS x", new QuerySettings().setFormat(ClickHouseFormat.JSON));
            }
        }
    }

    Output on main (8480ca001), ClickHouse 26.11.2.4:

    SELECT 1 as x FORMAT JSON -> column x: 1 | 
    EXPLAIN PLAN SELECT 1 -> column explain: Output: 1 |  | ReadFromSystemOne | 
    getClient() + FORMAT JSON -> format RowBinaryWithNamesAndTypes: ..x.UInt8.
    getClient() + setFormat(JSON) -> format JSON: { "meta": [ { "name": "x", "ty
    

    Output on main (8480ca001), ClickHouse 26.3.66.4:

    SELECT 1 as x FORMAT JSON -> java.sql.SQLException: Only RowBinaryWithNameAndTypes and JSONEachRow are supported for output format, but received format 'JSON'. Please check your query or 'format' property configuration.
    EXPLAIN PLAN SELECT 1 -> column explain: Expression ((Project names + (Projection + Change column names to column identifiers))) |   ReadFromSystemOne | 
    getClient() + FORMAT JSON -> format JSON: { "meta": [ { "name": "x", "ty
    getClient() + setFormat(JSON) -> format JSON: { "meta": [ { "name": "x", "ty
    

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

  9. added
    documentation
    jdbc
    and removed 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

    data-typesdocumentationenhancementjdbc

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions