Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ public String toString() {
} else if (view != null) {
sql += "VIEW " + view + " ";
}
sql += "IS " + comment;
// a null comment stands for PostgreSQL's COMMENT ON ... IS NULL, which removes the comment
sql += "IS " + (comment != null ? comment : "NULL");
return sql;
}

Expand Down
7 changes: 5 additions & 2 deletions src/main/jjtree/net/sf/jsqlparser/parser/JSqlParserCC.jjt
Original file line number Diff line number Diff line change
Expand Up @@ -15157,9 +15157,12 @@ Comment Comment():
<K_VIEW> view = Table() { result.setView(view); }
)
)
<K_IS> comment=<S_CHAR_LITERAL>
<K_IS>
(
comment=<S_CHAR_LITERAL> { result.setComment(new StringValue(comment.image)); }
| <K_NULL>
)
{
result.setComment(new StringValue(comment.image));
return result;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,36 @@ public void testCommentColumnDeparse() throws JSQLParserException {
@Test
public void testToString() {
Comment comment = new Comment();
assertEquals("COMMENT ON IS null", comment.toString());
assertEquals("COMMENT ON IS NULL", comment.toString());
}

@Test
public void testCommentTableIsNull() throws JSQLParserException {
String statement = "COMMENT ON TABLE schema1.table1 IS NULL";
Comment comment = (Comment) CCJSqlParserUtil.parse(statement);
assertEquals("table1", comment.getTable().getName());
assertThat(comment.getComment()).isNull();
assertSqlCanBeParsedAndDeparsed(statement);
}

@Test
public void testCommentColumnIsNull() throws JSQLParserException {
String statement = "COMMENT ON COLUMN table1.column1 IS NULL";
Comment comment = (Comment) CCJSqlParserUtil.parse(statement);
assertEquals("column1", comment.getColumn().getColumnName());
assertThat(comment.getComment()).isNull();
assertSqlCanBeParsedAndDeparsed(statement);
}

@Test
public void testCommentViewIsNull() throws JSQLParserException {
assertSqlCanBeParsedAndDeparsed("COMMENT ON VIEW myschema.myView IS NULL");
}

@Test
public void testCommentIsNullLowercase() throws JSQLParserException {
Comment comment = (Comment) CCJSqlParserUtil.parse("comment on table table1 is null");
assertThat(comment.getComment()).isNull();
}

@Test
Expand Down
Loading