diff --git a/documentation/reference/sql/drop.md b/documentation/reference/sql/drop.md index 31376480c..0e94af67a 100644 --- a/documentation/reference/sql/drop.md +++ b/documentation/reference/sql/drop.md @@ -20,7 +20,8 @@ permanently deletes all tables, all materialized views, and their contents on di ### IF EXISTS An optional `IF EXISTS` clause may be added directly after the `DROP TABLE` -keywords to indicate that the selected table should be dropped if it exists. +keywords to indicate that the selected table should be dropped only if it exists. +Without `IF EXISTS`, QuestDB will throw an error if the table does not exist. ## Description diff --git a/documentation/reference/sql/truncate.md b/documentation/reference/sql/truncate.md index 563aad67f..7f854be54 100644 --- a/documentation/reference/sql/truncate.md +++ b/documentation/reference/sql/truncate.md @@ -11,6 +11,12 @@ the table itself. ![Flow chart showing the syntax of the TRUNCATE TABLE keyword](/images/docs/diagrams/truncateTable.svg) +### IF EXISTS + +An optional `IF EXISTS` clause may be added directly after the `TRUNCATE TABLE` +keywords to indicate that the selected table should be truncated only if it exists. +Without `IF EXISTS`, QuestDB will throw an error if the table does not exist. + ## Notes This command irremediably deletes the data in the target table. In doubt, make @@ -19,9 +25,14 @@ sure you have created [backups](/docs/operations/backup/) of your data. ## Examples ```questdb-sql -TRUNCATE TABLE ratings; +TRUNCATE TABLE trades; ``` +This example will not throw an error, even if the table does not exist: + +```questdb-sql +TRUNCATE TABLE IF EXISTS trades_non_existent; +``` ## See also To delete both the data and the table structure, use diff --git a/static/images/docs/diagrams/.railroad b/static/images/docs/diagrams/.railroad index 6f011c785..b762bc643 100644 --- a/static/images/docs/diagrams/.railroad +++ b/static/images/docs/diagrams/.railroad @@ -349,7 +349,7 @@ show ) truncateTable - ::= 'TRUNCATE TABLE' tableName ';' + ::= 'TRUNCATE TABLE' ('IF' 'EXISTS')? tableName ';' explain ::= 'EXPLAIN' statement diff --git a/static/images/docs/diagrams/truncateTable.svg b/static/images/docs/diagrams/truncateTable.svg index 0516ddcde..b5dcf6eeb 100644 --- a/static/images/docs/diagrams/truncateTable.svg +++ b/static/images/docs/diagrams/truncateTable.svg @@ -1,4 +1,4 @@ - + \ No newline at end of file