Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
d2a-raudenaerde committed Jul 6, 2022
1 parent bf8a7db commit d119768
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/main/jjtree/net/sf/jsqlparser/parser/JSqlParserCC.jjt
Original file line number Diff line number Diff line change
Expand Up @@ -5451,7 +5451,15 @@ Truncate Truncate():
Table table;
}
{
<K_TRUNCATE> <K_TABLE>
/**
* TRUNCATE can be followed directly by the table name in Postgresql
* See: https://www.postgresql.org/docs/current/sql-truncate.html
*
* TRUNCATE [ TABLE ] [ ONLY ] name [ * ] [, ... ]
* [ RESTART IDENTITY | CONTINUE IDENTITY ] [ CASCADE | RESTRICT ]
*
*/
<K_TRUNCATE> [<K_TABLE>] [<K_ONLY>]
table=Table() { truncate.setTable(table); truncate.setCascade(false); } [ <K_CASCADE> {truncate.setCascade(true);} ]
{
return truncate;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,24 @@ public void testTruncate() throws Exception {
assertEquals(statement, truncate.toString());
}

@Test
public void testTruncatePostgresqlWithoutTableName() throws Exception {
String statement = "TRUncATE myschema.mytab";
Truncate truncate = (Truncate) parserManager.parse(new StringReader(statement));
assertEquals("myschema", truncate.getTable().getSchemaName());
assertEquals("myschema.mytab", truncate.getTable().getFullyQualifiedName());
assertEquals("TRUNCATE TABLE MYSCHEMA.MYTAB", truncate.toString().toUpperCase());

statement = "TRUncATE mytab";
String toStringStatement = "TRUncATE mytab";
truncate = (Truncate) parserManager.parse(new StringReader(statement));
assertEquals("mytab", truncate.getTable().getName());
assertEquals("TRUNCATE TABLE MYTAB", truncate.toString().toUpperCase());

statement = "TRUNCATE mytab CASCADE";
truncate = (Truncate) parserManager.parse(new StringReader(statement));
assertEquals("TRUNCATE TABLE MYTAB CASCADE", truncate.toString().toUpperCase());
}
@Test
public void testTruncateDeparse() throws JSQLParserException {
String statement = "TRUNCATE TABLE foo";
Expand Down

0 comments on commit d119768

Please sign in to comment.