Skip to content

Commit e4efa11

Browse files
committed
temp tbl
1 parent 2f40c85 commit e4efa11

File tree

5 files changed

+144
-51
lines changed

5 files changed

+144
-51
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
---
2+
title: system.temporary_tables
3+
---
4+
import FunctionDescription from '@site/src/components/FunctionDescription';
5+
6+
<FunctionDescription description="Introduced or updated: v1.2.666"/>
7+
8+
Provides information about all existing temporary tables in the current session.
9+
10+
```sql title='Examples:'
11+
SELECT * FROM system.temporary_tables;
12+
13+
┌────────────────────────────────────────────────────┐
14+
│ database │ name │ table_id │ engine │
15+
├──────────┼──────────┼─────────────────────┼────────┤
16+
│ default │ my_table │ 4611686018427407904 │ FUSE │
17+
└────────────────────────────────────────────────────┘
18+
```

docs/en/sql-reference/10-sql-commands/00-ddl/01-table/10-ddl-create-table-external-location.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
title: CREATE TABLE (external)
2+
title: CREATE EXTERNAL TABLE
33
sidebar_position: 2
44
---
55

docs/en/sql-reference/10-sql-commands/00-ddl/01-table/10-ddl-create-table.md

Lines changed: 7 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,17 @@ Databend aims to be easy to use by design and does NOT require any of those oper
2222
- [CREATE TABLE](#create-table): Creates a table from scratch.
2323
- [CREATE TABLE ... LIKE](#create-table--like): Creates a table with the same column definitions as an existing one.
2424
- [CREATE TABLE ... AS](#create-table--as): Creates a table and inserts data with the results of a SELECT query.
25-
- [CREATE TRANSIENT TABLE](#create-transient-table): Creates a table without storing its historical data for Time Travel.
26-
- [CREATE TABLE ... EXTERNAL_LOCATION](#create-table--external_location): Creates a table and specifies an S3 bucket for the data storage instead of the FUSE engine.
25+
26+
See also:
27+
28+
- [CREATE TEMP TABLE](10-ddl-create-temp-table.md)
29+
- [CREATE TRANSIENT TABLE](10-ddl-create-transient-table.md)
30+
- [CREATE EXTERNAL TABLE](10-ddl-create-table-external-location.md)
2731

2832
## CREATE TABLE
2933

3034
```sql
31-
CREATE [ OR REPLACE ] [ TRANSIENT ] TABLE [ IF NOT EXISTS ] [ <database_name>. ]<table_name>
35+
CREATE [ OR REPLACE ] TABLE [ IF NOT EXISTS ] [ <database_name>. ]<table_name>
3236
(
3337
<column_name> <data_type> [ NOT NULL | NULL ]
3438
[ { DEFAULT <expr> } ]
@@ -91,27 +95,6 @@ create table t_new compression='lz4' as select * from t_old;
9195
```
9296
:::
9397

94-
## CREATE TRANSIENT TABLE
95-
96-
Creates a transient table.
97-
98-
Transient tables are used to hold transitory data that does not require a data protection or recovery mechanism. Dataebend does not hold historical data for a transient table so you will not be able to query from a previous version of the transient table with the Time Travel feature, for example, the [AT](./../../20-query-syntax/03-query-at.md) clause in the SELECT statement will not work for transient tables. Please note that you can still [drop](./20-ddl-drop-table.md) and [undrop](./21-ddl-undrop-table.md) a transient table.
99-
100-
Transient tables help save your storage expenses because they do not need extra space for historical data compared to non-transient tables. See [example](#create-transient-table-1) for detailed explanations.
101-
102-
:::caution
103-
Concurrent modifications (including write operations) on transient tables may cause data corruption, making the data unreadable. This defect is being addressed. Until fixed, please avoid concurrent modifications on transient tables.
104-
:::
105-
106-
Syntax:
107-
```sql
108-
CREATE TRANSIENT TABLE ...
109-
```
110-
111-
## CREATE TABLE ... EXTERNAL_LOCATION
112-
113-
See [CREATE TABLE(EXTERNAL_LOCATION)](./10-ddl-create-table-external-location.md).
114-
11598
## Column Nullable
11699

117100
By default, **all columns are nullable(NULL)** in Databend. If you need a column that does not allow NULL values, use the NOT NULL constraint. For more information, see [NULL Values and NOT NULL Constraint](../../../00-sql-reference/10-data-types/index.md).
@@ -327,32 +310,6 @@ SELECT * FROM books_backup;
327310
+----+----------------+---------+
328311
```
329312

330-
### Create Transient Table
331-
332-
Create a transient table (temporary table) that automatically deletes data after a specified period of time:
333-
334-
```sql
335-
-- Create a transient table
336-
CREATE TRANSIENT TABLE visits (
337-
visitor_id BIGINT
338-
);
339-
340-
-- Insert values
341-
INSERT INTO visits VALUES(1);
342-
INSERT INTO visits VALUES(2);
343-
INSERT INTO visits VALUES(3);
344-
345-
-- Check the inserted data
346-
SELECT * FROM visits;
347-
+-----------+
348-
| visitor_id |
349-
+-----------+
350-
| 1 |
351-
| 2 |
352-
| 3 |
353-
+-----------+
354-
```
355-
356313
### Create Table ... Column As STORED | VIRTUAL
357314

358315
The following example demonstrates a table with a stored computed column that automatically recalculates based on updates to the "price" or "quantity" columns:
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
---
2+
title: CREATE TEMP TABLE
3+
sidebar_position: 1
4+
---
5+
import FunctionDescription from '@site/src/components/FunctionDescription';
6+
7+
<FunctionDescription description="Introduced or updated: v1.2.666"/>
8+
9+
Creates a temporary table that is automatically dropped at the end of the session.
10+
11+
- A temporary table is visible only within the session that created it and is automatically dropped, with all data vacuumed, when the session ends.
12+
- To show the existing temporary tables in the session, query the [system.temporary_tables](../../../00-sql-reference/20-system-tables/system-temp-tables.md) system table. See [Example-1](#example-1).
13+
- A temporary table with the same name as a normal table takes precedence, hiding the normal table until dropped. See [Example-2](#example-2).
14+
- No privileges are required to create or operate on a temporary table.
15+
- Databend supports creating temporary tables with both the [Fuse Engine](../../../00-sql-reference/30-table-engines/00-fuse.md) and [Memory Engine](../../../00-sql-reference/30-table-engines/01-memory.md).
16+
- To create temporary tables using BendSQL, ensure you are using the latest version of BendSQL.
17+
18+
## Syntax
19+
20+
```sql
21+
CREATE [ OR REPLACE ] { TEMPORARY | TEMP } TABLE
22+
[ IF NOT EXISTS ]
23+
[ <database_name>. ]<table_name>
24+
...
25+
```
26+
27+
The omitted parts follow the syntax of [CREATE TABLE](10-ddl-create-table.md).
28+
29+
## Examples
30+
31+
### Example-1
32+
33+
This example demonstrates how to create a temporary table and verify its existence by querying the [system.temporary_tables](../../../00-sql-reference/20-system-tables/system-temp-tables.md) system table:
34+
35+
```sql
36+
CREATE TEMP TABLE my_table (id INT, description STRING);
37+
38+
SELECT * FROM system.temporary_tables;
39+
40+
┌────────────────────────────────────────────────────┐
41+
│ database │ name │ table_id │ engine │
42+
├──────────┼──────────┼─────────────────────┼────────┤
43+
│ default │ my_table │ 4611686018427407904 │ FUSE │
44+
└────────────────────────────────────────────────────┘
45+
```
46+
47+
### Example-2
48+
49+
This example demonstrates how a temporary table with the same name as a normal table takes precedence. When both tables exist, operations target the temporary table, effectively hiding the normal table. Once the temporary table is dropped, the normal table becomes accessible again:
50+
51+
```sql
52+
-- Create a normal table
53+
CREATE TABLE my_table (id INT, name STRING);
54+
55+
-- Insert data into the normal table
56+
INSERT INTO my_table VALUES (1, 'Alice'), (2, 'Bob');
57+
58+
-- Create a temporary table with the same name
59+
CREATE TEMP TABLE my_table (id INT, description STRING);
60+
61+
-- Insert data into the temporary table
62+
INSERT INTO my_table VALUES (1, 'Temp Data');
63+
64+
-- Query the table: This will access the temporary table, hiding the normal table
65+
SELECT * FROM my_table;
66+
67+
┌────────────────────────────────────┐
68+
│ id │ description │
69+
├─────────────────┼──────────────────┤
70+
1 │ Temp Data │
71+
└────────────────────────────────────┘
72+
73+
-- Drop the temporary table
74+
DROP TABLE my_table;
75+
76+
-- Query the table again: Now the normal table is accessible
77+
SELECT * FROM my_table;
78+
79+
┌────────────────────────────────────┐
80+
│ id │ name │
81+
├─────────────────┼──────────────────┤
82+
1 │ Alice │
83+
2 │ Bob │
84+
└────────────────────────────────────┘
85+
```
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
---
2+
title: CREATE TRANSIENT TABLE
3+
sidebar_position: 1
4+
---
5+
6+
Creates a table without storing its historical data for Time Travel.
7+
8+
Transient tables are used to hold transitory data that does not require a data protection or recovery mechanism. Dataebend does not hold historical data for a transient table so you will not be able to query from a previous version of the transient table with the Time Travel feature, for example, the [AT](./../../20-query-syntax/03-query-at.md) clause in the SELECT statement will not work for transient tables. Please note that you can still [drop](./20-ddl-drop-table.md) and [undrop](./21-ddl-undrop-table.md) a transient table.
9+
10+
:::caution
11+
Concurrent modifications (including write operations) on transient tables may cause data corruption, making the data unreadable. This defect is being addressed. Until fixed, please avoid concurrent modifications on transient tables.
12+
:::
13+
14+
## Syntax
15+
16+
```sql
17+
CREATE [ OR REPLACE ] TRANSIENT TABLE
18+
[ IF NOT EXISTS ]
19+
[ <database_name>. ]<table_name>
20+
...
21+
```
22+
23+
The omitted parts follow the syntax of [CREATE TABLE](10-ddl-create-table.md).
24+
25+
## Examples
26+
27+
This examples creates a transient table named `visits`:
28+
29+
```sql
30+
CREATE TRANSIENT TABLE visits (
31+
visitor_id BIGINT
32+
);
33+
```

0 commit comments

Comments
 (0)