Skip to content

PreparedStatement against parameterized view causes sql-parser error #2547

@sniter

Description

@sniter
High Level Area Labels: 
 - jdbc-v2

Specific Area Labels:
  - sql-parser

Description

Steps to reproduce

  1. Create parameterized view
  2. Make prepared statement with query to parameterized view
  3. Run prepared statement

Error Log or Exception StackTrace

-- version 0.8.6
line 1:37 no viable alternative at input 'SELECTresultFROMtest_view(myParam='

-- version 0.9.1
SQL syntax error at line: 1, pos: 37, no viable alternative at input 'SELECTresultFROMtest_view(myParam='

Expected Behaviour

Code Example

String url = "jdbc:clickhouse://localhost:8123";
Properties properties = new Properties();
properties.setProperty("user", "user");
properties.setProperty("password", "password");
properties.setProperty("database", "default");
Connection connection = DriverManager.getConnection(url, properties);


// Creating view
Statement stmt = connection.createStatement()
stmt.execute("CREATE VIEW test_view AS SELECT {myParam:DateTime64(3)} as result");

// Prepare query to the view
PreparedStatement ps = conn.prepareStatement("SELECT result FROM test_view(myParam = ?)");
Instant expected = Instant.parse("2025-08-14T12:30:00.390Z");
LocalDateTime ldt = LocalDateTime.ofInstant(now, ZoneOffset.UTC);
ps.setObject(1, ldt);

ResultSet resultSet = ps.executeQuery();
resultSet.next();
Instant actual = ((java.sql.Timestamp)resultSet.getObject("result")).toInstant();
System.out.println(actual);

Environment

  • Cloud
  • Client version: 0.8.6, 0.9.1
  • Language version: openjdk version "21.0.8" 2025-07-15
  • OS: Max OS 15.6

ClickHouse Server

  • ClickHouse Server version: 25.3.4

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions