Skip to content

Commit 7c090bc

Browse files
authored
truncate if exists (#250)
1 parent 03868f3 commit 7c090bc

File tree

4 files changed

+31
-13
lines changed

4 files changed

+31
-13
lines changed

documentation/reference/sql/drop.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ permanently deletes all tables, all materialized views, and their contents on di
2020
### IF EXISTS
2121

2222
An optional `IF EXISTS` clause may be added directly after the `DROP TABLE`
23-
keywords to indicate that the selected table should be dropped if it exists.
23+
keywords to indicate that the selected table should be dropped only if it exists.
24+
Without `IF EXISTS`, QuestDB will throw an error if the table does not exist.
2425

2526
## Description
2627

documentation/reference/sql/truncate.md

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,12 @@ the table itself.
1111

1212
![Flow chart showing the syntax of the TRUNCATE TABLE keyword](/images/docs/diagrams/truncateTable.svg)
1313

14+
### IF EXISTS
15+
16+
An optional `IF EXISTS` clause may be added directly after the `TRUNCATE TABLE`
17+
keywords to indicate that the selected table should be truncated only if it exists.
18+
Without `IF EXISTS`, QuestDB will throw an error if the table does not exist.
19+
1420
## Notes
1521

1622
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.
1925
## Examples
2026

2127
```questdb-sql
22-
TRUNCATE TABLE ratings;
28+
TRUNCATE TABLE trades;
2329
```
2430

31+
This example will not throw an error, even if the table does not exist:
32+
33+
```questdb-sql
34+
TRUNCATE TABLE IF EXISTS trades_non_existent;
35+
```
2536
## See also
2637

2738
To delete both the data and the table structure, use

static/images/docs/diagrams/.railroad

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,7 @@ show
349349
)
350350

351351
truncateTable
352-
::= 'TRUNCATE TABLE' tableName ';'
352+
::= 'TRUNCATE TABLE' ('IF' 'EXISTS')? tableName ';'
353353

354354
explain
355355
::= 'EXPLAIN' statement

static/images/docs/diagrams/truncateTable.svg

Lines changed: 16 additions & 10 deletions
Loading

0 commit comments

Comments
 (0)