File tree Expand file tree Collapse file tree
test/java/com/clickhouse/jdbc Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -529,7 +529,7 @@ void dataClause(): {} {
529529 <RPAREN> { token_source.removePosition(ClickHouseSqlStatement.KEYWORD_VALUES_END); }
530530 )*
531531 ( settingsPart() )?
532- | (LOOKAHEAD(2) (<SELECT> { token_source.addPosition(token); } columnExprList() <FROM>
532+ | (LOOKAHEAD(2) ((withClause())? <SELECT> { token_source.addPosition(token); } columnExprList() <FROM>
533533 <INPUT> <LPAREN> <STRING_LITERAL> { token_source.input = ClickHouseSqlUtils.unescape(token.image); } <RPAREN>)?
534534 <FORMAT> <IDENTIFIER> { token_source.format = token.image; } )? (anyExprList())?
535535 } catch (ParseException e) {
Original file line number Diff line number Diff line change @@ -513,4 +513,30 @@ public void testQueryWithNamedParameter() throws SQLException {
513513 Assert .assertFalse (rs .next ());
514514 }
515515 }
516+
517+ @ Test (groups = "integration" )
518+ public void testInsertWithAndSelect () throws Exception {
519+ try (ClickHouseConnection conn = newConnection (new Properties ());
520+ Statement s = conn .createStatement ()) {
521+ s .execute ("drop table if exists test_insert_with_and_select; "
522+ + "CREATE TABLE test_insert_with_and_select(value String) ENGINE=Memory" );
523+ try (PreparedStatement ps = conn .prepareStatement (
524+ "INSERT INTO test_insert_with_and_select(value) WITH t as ( SELECT 'testValue1') SELECT * FROM t" )) {
525+ ps .executeUpdate ();
526+ }
527+
528+ try (PreparedStatement ps = conn .prepareStatement (
529+ "INSERT INTO test_insert_with_and_select(value) WITH t as ( SELECT 'testValue2' as value) SELECT * FROM t WHERE value != ?" )) {
530+ ps .setString (1 , "" );
531+ ps .executeUpdate ();
532+ }
533+
534+ ResultSet rs = s .executeQuery ("select * from test_insert_with_and_select order by value" );
535+ Assert .assertTrue (rs .next ());
536+ Assert .assertEquals (rs .getString ("Value" ), "testValue1" );
537+ Assert .assertTrue (rs .next ());
538+ Assert .assertEquals (rs .getString ("VALUE" ), "testValue2" );
539+ Assert .assertFalse (rs .next ());
540+ }
541+ }
516542}
You can’t perform that action at this time.
0 commit comments