Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
c34b724
Initial commit
shnikd Jun 2, 2025
3ef0155
Fixes
shnikd Jun 2, 2025
327406b
Fixes
shnikd Jun 2, 2025
a77906c
Fixes
shnikd Jun 2, 2025
57cad16
Fixes
shnikd Jun 2, 2025
b990617
Fixes
shnikd Jun 2, 2025
ac5b527
Fixes
shnikd Jun 2, 2025
5292332
Fixes
shnikd Jun 2, 2025
db29062
Fixes
shnikd Jun 2, 2025
db415b3
Fixes
shnikd Jun 2, 2025
23ca11c
Fixes
shnikd Jun 2, 2025
ba32fea
Fixes
shnikd Jun 2, 2025
7a2e69c
Fixes
shnikd Jun 2, 2025
537485e
Update ydb/docs/en/core/yql/reference/syntax/show_create.md
shnikd Jun 4, 2025
c5384af
Update ydb/docs/en/core/yql/reference/syntax/show_create.md
shnikd Jun 4, 2025
0f09d77
Update ydb/docs/en/core/yql/reference/syntax/show_create.md
shnikd Jun 4, 2025
45dd629
Update ydb/docs/en/core/yql/reference/syntax/show_create.md
shnikd Jun 4, 2025
57ad305
Update ydb/docs/ru/core/yql/reference/syntax/show_create.md
shnikd Jun 5, 2025
c9ff204
Update ydb/docs/ru/core/yql/reference/syntax/show_create.md
shnikd Jun 5, 2025
2d36c03
Update ydb/docs/en/core/yql/reference/syntax/show_create.md
shnikd Jun 5, 2025
21a24e3
Update ydb/docs/ru/core/yql/reference/syntax/show_create.md
shnikd Jun 5, 2025
c433fd9
Fixes
shnikd Jun 5, 2025
b2a8977
Fixes
shnikd Jun 5, 2025
b708055
Update ydb/docs/en/core/yql/reference/syntax/show_create.md
shnikd Jun 9, 2025
a91d77d
Update ydb/docs/en/core/yql/reference/syntax/show_create.md
shnikd Jun 9, 2025
3647d67
Update ydb/docs/en/core/yql/reference/syntax/show_create.md
shnikd Jun 9, 2025
8a7c564
Fixes
shnikd Jun 9, 2025
1f30ad3
Fixes
shnikd Jun 9, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions ydb/docs/en/core/yql/reference/syntax/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
* [CREATE TABLE](create_table/index.md)
* [DROP TABLE](drop_table.md)
* [INSERT](insert_into.md)
* [SHOW CREATE](show_create.md)

{% if feature_map_tables %}

Expand Down
127 changes: 127 additions & 0 deletions ydb/docs/en/core/yql/reference/syntax/show_create.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
# SHOW CREATE

`SHOW CREATE` returns a query required to recreate the structure of the specified object: a [table](../../../concepts/datamodel/table.md) or [view](../../../concepts/datamodel/view.md). The returned query may contain multiple DDL statements.

## Syntax

```yql
SHOW CREATE [TABLE|VIEW] <name>;
```

## Parameters

* `TABLE|VIEW` — The object type. Valid values are `TABLE` or `VIEW`.
* `<name>` — The object name. An absolute path may also be specified.

## Result

The command always returns **exactly one row** with three columns:

| Path | PathType | CreateQuery |
|-----------------|------------|----------------------------------|
| Path | Table/View | DDL statements for creation |

- **Path** — The path to the object (for example, `MyTable` or `MyView`).
- **PathType** — The type of object: `Table` or `View`.
- **CreateQuery** — The complete set of DDL statements needed to create the object:
- For tables: the main [CREATE TABLE](create_table/index.md) statement (with the path relative to the database root), plus any additional statements describing the current configuration, such as:
- [ALTER TABLE ... ALTER INDEX](alter_table/secondary_index#alter-index) — for index partitioning settings.
- [ALTER TABLE ... ADD CHANGEFEED](alter_table/changefeed.md) — for adding a changefeed.
- `ALTER SEQUENCE` — for restoring a `Sequence` state for `Serial` columns.
- For views: the definition via [CREATE VIEW](create-view.md), and, if necessary, the statements the view has captured from the creation context, for example, [PRAGMA TablePathPrefix](pragma#table-path-prefix).


## Examples

### Row-oriented tables

```yql
SHOW CREATE TABLE my_table;
```

| Path | PathType | CreateQuery |
|-----------------|-----------|---------------------------------|
| `my_table` | `Table` | `CREATE TABLE...` — see below |

```yql
CREATE TABLE `my_table` (
`Key1` Uint32 NOT NULL,
`Key2` Utf8 NOT NULL,
`Key3` Serial4 NOT NULL,
`Value1` Utf8 FAMILY `my_family`,
`Value2` Bool,
`Value3` String,
INDEX `my_index` GLOBAL SYNC ON (`Key2`, `Value1`, `Value2`),
FAMILY `my_family` (COMPRESSION = 'lz4'),
PRIMARY KEY (`Key1`, `Key2`, `Key3`)
)
WITH (
AUTO_PARTITIONING_BY_SIZE = ENABLED,
AUTO_PARTITIONING_PARTITION_SIZE_MB = 1000
);

ALTER TABLE `my_table`
ADD CHANGEFEED `feed_3` WITH (MODE = 'KEYS_ONLY', FORMAT = 'JSON', RETENTION_PERIOD = INTERVAL('PT30M'), TOPIC_MIN_ACTIVE_PARTITIONS = 3)
;

ALTER SEQUENCE `/Root/my_table/_serial_column_Key3` START WITH 101 INCREMENT BY 404 RESTART;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this the only place that uses an absolute path?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Для alter sequence сейчас поддерживается только абсолютный путь


ALTER TABLE `my_table`
ALTER INDEX `my_index` SET (AUTO_PARTITIONING_BY_LOAD = ENABLED, AUTO_PARTITIONING_MIN_PARTITIONS_COUNT = 1000, AUTO_PARTITIONING_MAX_PARTITIONS_COUNT = 5000)
;
```

### Column-oriented tables

```yql
SHOW CREATE TABLE my_table;
```

| Path | PathType | CreateQuery |
|-----------------|-----------|---------------------------------|
| `my_table` | `Table` | `CREATE TABLE...` — see below |

```yql
CREATE TABLE `my_table` (
`Key1` Uint64 NOT NULL,
`Key2` Utf8 NOT NULL,
`Key3` Int32 NOT NULL,
`Value1` Utf8,
`Value2` Int16,
`Value3` String,
FAMILY `default` (COMPRESSION = 'zstd'),
FAMILY `Family1` (COMPRESSION = 'off'),
FAMILY `Family2` (COMPRESSION = 'lz4'),
PRIMARY KEY (`Key1`, `Key2`, `Key3`)
)
PARTITION BY HASH (`Key1`, `Key2`)
WITH (
STORE = COLUMN,
AUTO_PARTITIONING_MIN_PARTITIONS_COUNT = 100,
TTL =
INTERVAL('PT10S') TO EXTERNAL DATA SOURCE `/Root/tier1`,
INTERVAL('PT1H') DELETE
ON Key1 AS SECONDS
);
```

### Views

```yql
SHOW CREATE VIEW my_view;
```

| Path | PathType | CreateQuery |
|-----------------|-----------|-------------------------------------------|
| `my_view` | `View` | `PRAGMA TablePathPrefix...` — see below |

```yql
PRAGMA TablePathPrefix = '/Root/DirA/DirB/DirC';

CREATE VIEW `my_view` WITH (security_invoker = TRUE) AS
SELECT
*
FROM
test_table
;
```
1 change: 1 addition & 0 deletions ydb/docs/en/core/yql/reference/syntax/toc_i.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ items:
- { name: SELECT, include: { mode: link, path: select/toc_p.yaml } }
- { name: SELECT STREAM, href: select_stream.md, when: feature_mapreduce and process_command == "PROCESS STREAM" }
- { name: SUBQUERY, href: subquery.md, when: feature_subquery }
- { name: SHOW CREATE, href: show_create.md }
Copy link

Copilot AI Jun 2, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the SHOW CREATE command is intended to be feature gated like some other entries, consider adding a 'when' condition to ensure consistent documentation of its availability.

Copilot uses AI. Check for mistakes.
- { name: UPDATE, href: update.md, when: feature_map_tables }
- { name: UPSERT, href: upsert_into.md, when: feature_upsert }
- { name: USE, href: use.md, when: feature_mapreduce }
Expand Down
1 change: 1 addition & 0 deletions ydb/docs/ru/core/yql/reference/syntax/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
* [CREATE TABLE](create_table/index.md)
* [DROP TABLE](drop_table.md)
* [INSERT](insert_into.md)
* [SHOW CREATE](show_create.md)

{% if feature_map_tables %}

Expand Down
127 changes: 127 additions & 0 deletions ydb/docs/ru/core/yql/reference/syntax/show_create.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
# SHOW CREATE

`SHOW CREATE` возвращает запрос, возможно состоящий из нескольких DDL-выражений, необходимых для воссоздания структуры выбранного объекта: [таблицы](../../../concepts/datamodel/table.md) или [представления](../../../concepts/datamodel/view.md).

## Синтаксис

```yql
SHOW CREATE [TABLE|VIEW] <name>;
```

## Параметры

* `TABLE|VIEW` - тип объекта: `TABLE` для таблицы или `VIEW` для представления.
* `<name>` - имя объекта, также может быть указан абсолютный путь до объекта.

## Результат выполнения

Команда возвращает **ровно одну строку** с тремя колонками:

| Path | PathType | CreateQuery |
|-----------------|------------|------------------------------------|
| Путь | Table/View | DDL-выражения для создания объекта |

- **Path** — путь к объекту (например, `MyTable` или `MyView`).
- **PathType** — тип объекта: `Table` или `View`.
- **CreateQuery** — полный набор DDL-выражений, необходимых для создания объекта:
- Для таблиц: основной оператор [CREATE TABLE](create_table/index.md) (с путем относительно базы), а также дополнительные команды, необходимые для описания текущего состояния и настроек:
- [ALTER TABLE ... ALTER INDEX](alter_table/secondary_index#alter-index)— для задания настроек партицирования вторичных индексов.
- [ALTER TABLE ... ADD CHANGEFEED](alter_table/changefeed.md)— для добавления потока изменений.
- `ALTER SEQUENCE` — для восстановления состояния `Sequence` у колонок типа [Serial](../../../yql/reference/types/serial.md).
- Для представлений: определение посредством команды [CREATE VIEW](create-view.md), а также, если необходимо, выражения, которые были зафиксированы представлением из контекста создания, например, [PRAGMA TablePathPrefix](pragma#table-path-prefix).

## Примеры

### Строковые таблицы

```yql
SHOW CREATE TABLE my_table;
```

| Path | PathType | CreateQuery |
|-----------------|-----------|--------------------------------|
| `my_table` | `Table` | `CREATE TABLE...` - см. ниже |

```yql
CREATE TABLE `my_table` (
`Key1` Uint32 NOT NULL,
`Key2` Utf8 NOT NULL,
`Key3` Serial4 NOT NULL,
`Value1` Utf8 FAMILY `my_family`,
`Value2` Bool,
`Value3` String,
INDEX `my_index` GLOBAL SYNC ON (`Key2`, `Value1`, `Value2`),
FAMILY `my_family` (COMPRESSION = 'lz4'),
PRIMARY KEY (`Key1`, `Key2`, `Key3`)
)
WITH (
AUTO_PARTITIONING_BY_SIZE = ENABLED,
AUTO_PARTITIONING_PARTITION_SIZE_MB = 1000
);

ALTER TABLE `my_table`
ADD CHANGEFEED `feed_3` WITH (MODE = 'KEYS_ONLY', FORMAT = 'JSON', RETENTION_PERIOD = INTERVAL('PT30M'), TOPIC_MIN_ACTIVE_PARTITIONS = 3)
;

ALTER SEQUENCE `/Root/my_table/_serial_column_Key3` START WITH 101 INCREMENT BY 404 RESTART;

ALTER TABLE `my_table`
ALTER INDEX `my_index` SET (AUTO_PARTITIONING_BY_LOAD = ENABLED, AUTO_PARTITIONING_MIN_PARTITIONS_COUNT = 1000, AUTO_PARTITIONING_MAX_PARTITIONS_COUNT = 5000)
;
```

### Колоночные таблицы

```yql
SHOW CREATE TABLE my_table;
```

| Path | PathType | CreateQuery |
|-----------------|-----------|--------------------------------|
| `my_table` | `Table` | `CREATE TABLE...` - см. ниже |

```yql
CREATE TABLE `my_table` (
`Key1` Uint64 NOT NULL,
`Key2` Utf8 NOT NULL,
`Key3` Int32 NOT NULL,
`Value1` Utf8,
`Value2` Int16,
`Value3` String,
FAMILY `default` (COMPRESSION = 'zstd'),
FAMILY `Family1` (COMPRESSION = 'off'),
FAMILY `Family2` (COMPRESSION = 'lz4'),
PRIMARY KEY (`Key1`, `Key2`, `Key3`)
)
PARTITION BY HASH (`Key1`, `Key2`)
WITH (
STORE = COLUMN,
AUTO_PARTITIONING_MIN_PARTITIONS_COUNT = 100,
TTL =
INTERVAL('PT10S') TO EXTERNAL DATA SOURCE `/Root/tier1`,
INTERVAL('PT1H') DELETE
ON Key1 AS SECONDS
);
```

### Представления

```yql
SHOW CREATE VIEW my_view;
```

| Path | PathType | CreateQuery |
|-----------------|-----------|------------------------------------------|
| `my_view` | `View` | `PRAGMA TablePathPrefix...` - см. ниже |

```yql
PRAGMA TablePathPrefix = '/Root/DirA/DirB/DirC';

CREATE VIEW `my_view` WITH (security_invoker = TRUE) AS
SELECT
*
FROM
test_table
;
```

1 change: 1 addition & 0 deletions ydb/docs/ru/core/yql/reference/syntax/toc_i.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ items:
- { name: REVOKE, href: revoke.md, when: feature_user_and_group }
- { name: SELECT, include: { mode: link, path: select/toc_p.yaml } }
- { name: SELECT STREAM, href: select_stream.md, when: feature_mapreduce and process_command == "PROCESS STREAM" }
- { name: SHOW CREATE, href: show_create.md }
Copy link

Copilot AI Jun 2, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the SHOW CREATE command is meant to be controlled by a feature flag similar to other commands, consider adding an appropriate 'when' condition so that its availability is clearly documented.

Copilot uses AI. Check for mistakes.
- { name: SUBQUERY, href: subquery.md, when: feature_subquery }
- { name: UPDATE, href: update.md, when: feature_map_tables }
- { name: UPSERT, href: upsert_into.md, when: feature_upsert }
Expand Down