File tree Expand file tree Collapse file tree
main/jjtree/net/sf/jsqlparser/parser
test/java/net/sf/jsqlparser/statement/truncate Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -5451,7 +5451,15 @@ Truncate Truncate():
54515451 Table table;
54525452}
54535453{
5454- <K_TRUNCATE> <K_TABLE>
5454+ /**
5455+ * TRUNCATE can be followed directly by the table name in Postgresql
5456+ * See: https://www.postgresql.org/docs/current/sql-truncate.html
5457+ *
5458+ * TRUNCATE [ TABLE ] [ ONLY ] name [ * ] [, ... ]
5459+ * [ RESTART IDENTITY | CONTINUE IDENTITY ] [ CASCADE | RESTRICT ]
5460+ *
5461+ */
5462+ <K_TRUNCATE> [<K_TABLE>] [<K_ONLY>]
54555463 table=Table() { truncate.setTable(table); truncate.setCascade(false); } [ <K_CASCADE> {truncate.setCascade(true);} ]
54565464 {
54575465 return truncate;
Original file line number Diff line number Diff line change @@ -41,6 +41,24 @@ public void testTruncate() throws Exception {
4141 assertEquals (statement , truncate .toString ());
4242 }
4343
44+ @ Test
45+ public void testTruncatePostgresqlWithoutTableName () throws Exception {
46+ String statement = "TRUncATE myschema.mytab" ;
47+ Truncate truncate = (Truncate ) parserManager .parse (new StringReader (statement ));
48+ assertEquals ("myschema" , truncate .getTable ().getSchemaName ());
49+ assertEquals ("myschema.mytab" , truncate .getTable ().getFullyQualifiedName ());
50+ assertEquals ("TRUNCATE TABLE MYSCHEMA.MYTAB" , truncate .toString ().toUpperCase ());
51+
52+ statement = "TRUncATE mytab" ;
53+ String toStringStatement = "TRUncATE mytab" ;
54+ truncate = (Truncate ) parserManager .parse (new StringReader (statement ));
55+ assertEquals ("mytab" , truncate .getTable ().getName ());
56+ assertEquals ("TRUNCATE TABLE MYTAB" , truncate .toString ().toUpperCase ());
57+
58+ statement = "TRUNCATE mytab CASCADE" ;
59+ truncate = (Truncate ) parserManager .parse (new StringReader (statement ));
60+ assertEquals ("TRUNCATE TABLE MYTAB CASCADE" , truncate .toString ().toUpperCase ());
61+ }
4462 @ Test
4563 public void testTruncateDeparse () throws JSQLParserException {
4664 String statement = "TRUNCATE TABLE foo" ;
You can’t perform that action at this time.
0 commit comments