Uploaded image for project: 'Calcite'
  1. Calcite
  2. CALCITE-4820

INSERT Queries have keyword ROW inserted VALUES

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Open
    • Major
    • Resolution: Unresolved
    • 1.27.0
    • None
    • jdbc-adapter
    • None

    Description

      When parsing INSERT queries, Calcite inserts the keyword ROW in the VALUES clause.  This causes queries to fail in MySQL and other databases.  

      The function below produces the following output:

      INSERT INTO mysql_test.data_types 
      VALUES(1, 2, 3.0, 4.0, '5.0', '2020-12-31', '12:00:00', '2015-12-30 17:55:55')

      Converted into:

      Postgres: INSERT INTO "postgresl_test"."data_types"
      VALUES ROW(1, 2, 3.0, 4.0, '5.0', '2020-12-31', '12:00:00', '2015-12-30 17:55:55')
      MySQL: INSERT INTO `mysql_test`.`data_types`
      VALUES ROW(1, 2, 3.0, 4.0, '5.0', '2020-12-31', '12:00:00', '2015-12-30 17:55:55')
      MSSQL: INSERT INTO [mssql_test].[data_types]
      VALUES ROW(1, 2, 3.0, 4.0, '5.0', '2020-12-31', '12:00:00', '2015-12-30 17:55:55')

      Ideally, the end result should be a valid INSERT query for the dialect used, and without the ROW keyword in the VALUES clause.

       

      public static String cleanQuery(String query, SqlDialect dialect) {
        SqlParser.Config sqlParserConfig = SqlParser.configBuilder()
          .setParserFactory(SqlDdlParserImpl.FACTORY)
          .setConformance(SqlConformanceEnum.MYSQL_5)
          .setCaseSensitive(true)
          .setLex(Lex.MYSQL)
          .build();

        try {
          SqlNode node = SqlParser.create(query, sqlParserConfig).parseQuery();
          return node.toSqlString(dialect).getSql();
        } catch (SqlParseException e) {
          return null;
      {{  }}}
      }

      Attachments

        Issue Links

          Activity

            People

              Unassigned Unassigned
              cgivre Charles Givre
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated: