Skip to content

Commit

Permalink
add SHOW CREATE TABLE tbl
Browse files Browse the repository at this point in the history
  • Loading branch information
nwoolmer committed Dec 5, 2024
1 parent b219779 commit b37330b
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 11 deletions.
46 changes: 46 additions & 0 deletions documentation/reference/sql/show.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ and partition storage size on disk.
- `SHOW` returns all the tables.
- `SHOW COLUMNS` returns all the columns and their metadata for the selected
table.
- `SHOW CREATE TABLE` returns a DDL query that allows you to recreate the table.
- `SHOW PARTITIONS` returns the partition information for the selected table.
- `SHOW PARAMETERS` shows configuration keys and their matching `env_var_name`,
their values and the source of the value
Expand Down Expand Up @@ -60,6 +61,51 @@ SHOW COLUMNS FROM my_table;
| ts | TIMESTAMP | false | 0 | false | 0 | true |
| s | STRING | false | 0 | false | 0 | false |


### SHOW CREATE TABLE

```questdbl-sql title="retrieving table ddl" demo
SHOW CREATE TABLE trades;
```

| ddl |
|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| CREATE TABLE trades (symbol SYMBOL CAPACITY 256 CACHE, side SYMBOL CAPACITY 256 CACHE, price DOUBLE, amount DOUBLE, timestamp TIMESTAMP) timestamp(timestamp) PARTITION BY DAY WAL WITH maxUncommittedRows=500000, o3MaxLag=600000000us; |

This is printed with formatting, so when pasted into a text editor that support formatting characters, you will see:

```questdb-sql
CREATE TABLE trades (
symbol SYMBOL CAPACITY 256 CACHE,
side SYMBOL CAPACITY 256 CACHE,
price DOUBLE,
amount DOUBLE,
timestamp TIMESTAMP
) timestamp(timestamp) PARTITION BY DAY WAL
WITH maxUncommittedRows=500000, o3MaxLag=600000000us;
```

#### Enterprise variant

QuestDB Enterprise will include an additional `OWNED BY` clause populated with the current user.

For example,

```questdb-sql
CREATE TABLE trades (
symbol SYMBOL CAPACITY 256 CACHE,
side SYMBOL CAPACITY 256 CACHE,
price DOUBLE,
amount DOUBLE,
timestamp TIMESTAMP
) timestamp(timestamp) PARTITION BY DAY WAL
WITH maxUncommittedRows=500000, o3MaxLag=600000000us
OWNED BY 'admin';
```

This clause assigns permissions for the table to that user. If permissions should be assigned to a different user,
please modify this clause appropriately.

### SHOW PARTITIONS

```questdb-sql
Expand Down
12 changes: 1 addition & 11 deletions static/images/docs/diagrams/.railroad
Original file line number Diff line number Diff line change
Expand Up @@ -311,17 +311,7 @@ update
(FROM 'joinTable1' (JOIN 'joinTable2' ON 'joinCondition2')? )? (WHERE 'filter')?

show
::= 'SHOW' ( ('TABLES'|('COLUMNS'|'PARTITIONS') 'FROM' tableName ) | 'USER' userName? | 'USERS' | 'GROUPS' userName? | 'SERVICE' 'ACCOUNT' accountName? | 'SERVICE' 'ACCOUNTS' userName? | 'PERMISSIONS' entityName? | 'SERVER_VERSION' | 'SERVER_CONF' )

- `SHOW USER` shows user secret (enterprise-only)
- `SHOW USERS` shows all users (enterprise-only)
- `SHOW GROUPS` shows all groups the user belongs or all groups in the system (enterprise-only)
- `SHOW SERVER_VERSION` displays PostgreSQL compatibility version
- `SHOW SERVICE ACCOUNTS` displays all service accounts or those assigned to the user/group (enterprise-only)
- `SHOW SERVICE ACCOUNT` displays details of a service account (enterprise-only)
- `SHOW PERMISSIONS` displays permissions of user, group or service account (enterprise-only)
- `SHOW SERVER_CONF` shows the content of QuestDB's server.conf configuration file. (enterprise-only)

::= 'SHOW' ( ('TABLES'|('COLUMNS'|'PARTITIONS') 'FROM' tableName ) | 'CREATE' 'TABLE' tableName | 'USER' userName? | 'USERS' | 'GROUPS' userName? | 'SERVICE' 'ACCOUNT' accountName? | 'SERVICE' 'ACCOUNTS' userName? | 'PERMISSIONS' entityName? | 'SERVER_VERSION' | 'SERVER_CONF' )

truncateTable
::= 'TRUNCATE TABLE' tableName ';'
Expand Down

0 comments on commit b37330b

Please sign in to comment.