Skip to content

[BUG] JSQLParser 4.7: ADD COLUMN IF NOT EXISTS not supported #1875

Closed

Description

@zdhuangelephant

Always check against the Latest SNAPSHOT of JSQLParser and the Syntax Diagram

Failing SQL Feature:

  • Brief description of the failing SQL feature

  • Example: Encountered unexpected token: "IF" "IF" can't be parsed

  • run java `static void buildCCJSqlParser() throws IOException, JSQLParserException {

      final Path path = Paths.get("/Users/xxx/xxx", "xxx-xxx-comm.sql");
      final byte[] bytes = Files.readAllBytes(path);
    
      ExecutorService executorService = Executors.newSingleThreadExecutor();
    
      final CCJSqlParser ccjSqlParser = CCJSqlParserUtil.newParser(new ByteArrayInputStream(bytes), StandardCharsets.UTF_8.name());
      final Statements statements = CCJSqlParserUtil.parseStatements(ccjSqlParser, executorService);
    
      final int[] updateCounter = {0};
      final int[] alterCounter = {0};
      final int[] selectCounter = {0};
      StatementVisitorAdapter adapter = new StatementVisitorAdapter(){
          @Override
          public void visit(Update update) {
              final String name = update.getTable().getName();
              final String schemaName = update.getTable().getSchemaName();
    
              updateCounter[0]++;
              System.out.printf("Update: table:%s, schema:%s%n", name, schemaName);
          }
          @Override
          public void visit(Alter alter) {
              final String name = alter.getTable().getName();
              final String schemaName = alter.getTable().getSchemaName();
    
              alterCounter[0]++;
              System.out.printf("Update: table:%s, schema:%s%n", name, schemaName);
          }
      };
      statements.accept(adapter);
    
      System.out.println(updateCounter[0] + ", " + alterCounter[0] + ", " + selectCounter[0]);
    

    }`

SQL Example:

  • Simplified Query Example, focusing on the failing feature
    -- Replace with your ACTUAL example
    ALTER TABLE IF EXISTS usercenter.dict_surgeries ADD COLUMN IF NOT EXISTS operation_grade_id int8 NULL;

Software Information:

  • JSqlParser version 4.7
  • Database (PostgreSQL )

Tips:

Please write in English and avoid Screenshots (as we can't copy and paste content from it).
Try your example online with the latest JSQLParser and share the link in the error report.
Do provide Links or References to the specific Grammar and Syntax you are trying to use.

Activity

  1. manticore-projects commented on Oct 11, 2023

    @manticore-projects
    Contributor

    Greetings,

    the IF NOT EXISTS clause is not supported for ADD COLUMN.

    You can try it online here.

    Reference to the supported SQL Syntax.

    In my opinion all the DDL statements deserve a proper refactoring and we are looking for Sponsors or Volunteers.

  2. changed the title [-][BUG] JSQLParser Version : RDBMS : failing feature description[/-] [+][BUG] JSQLParser 4.7: `ADD COLUMN IF NOT EXISTS` not supported[/+] on Oct 11, 2023
  3. zdhuangelephant commented on Oct 12, 2023

    @zdhuangelephant
    Author

    thank you for your time to reply this question.
    the volunteers? it's excited when i as a committer

  4. manticore-projects commented on Oct 12, 2023

    @manticore-projects
    Contributor

    the volunteers? it's excited when i as a committer

    Please follow the guide: https://manticore-projects.com/JSQLParser/contribution.html
    We will be most excited to welcome you as a new contributor. Fell very welcome to ask any questions.

  5. jxnu-liguobin commented on Jan 31, 2024

    @jxnu-liguobin
    Contributor

    Seems to require refactoring for add alter modify drop column

  6. minleejae commented on Sep 4, 2026

    @minleejae
    Contributor

    @manticore-projects This was fixed by #1957, with regression coverage for the reported SQL. Could you please close this issue?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions