Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Document alter...swap with in sql command #88

Merged
merged 3 commits into from
Nov 27, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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 mint.json
Original file line number Diff line number Diff line change
Expand Up @@ -467,6 +467,7 @@
"sql/commands/sql-alter-schema",
"sql/commands/sql-alter-sink",
"sql/commands/sql-alter-source",
"sql/commands/sql-alter-swap",
"sql/commands/sql-alter-system",
"sql/commands/sql-alter-table",
"sql/commands/sql-alter-user",
Expand Down
18 changes: 18 additions & 0 deletions sql/commands/sql-alter-materialized-view.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -112,3 +112,21 @@ ALTER MATERIALIZED VIEW mv1 SET BACKFILL_RATE_LIMIT=DEFAULT;
<Note>
To modify the rate limit of the sources used in the materialized view, please refer to [SET SOURCE_RATE_LIMIT](/sql/commands/sql-alter-source#set-source-rate-limit).
</Note>

### `SWAP WITH`

```sql
ALTER MATERIALIZED VIEW name
SWAP WITH target_name;
```

| Parameter | Description |
| :-------- | :---------- |
| _name_ | The current name of the materialized view to swap. |
| _target_name_ | The target name of the materialized view you want to swap with. |

```sql
-- Swap the names of the sales_summary materialized view and the sales_archive materialized view.
ALTER MATERIALIZED VIEW sales_summary
SWAP WITH sales_archive;
```
18 changes: 18 additions & 0 deletions sql/commands/sql-alter-sink.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -87,3 +87,21 @@ ALTER SINK sink_name
-- Change the name of the sink named "sink0" to "sink1"
ALTER SINK sink0 RENAME TO sink1;
```

### `SWAP WITH`

```sql
ALTER SINK name
SWAP WITH target_name;
```

| Parameter | Description |
| :-------- | :---------- |
| _name_ | The current name of the sink to swap. |
| _target_name_ | The target name of the sink you want to swap with. |

```sql
-- Swap the names of the log_sink sink and the error_sink sink.
ALTER SINK log_sink
SWAP WITH error_sink;
```
18 changes: 18 additions & 0 deletions sql/commands/sql-alter-source.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -188,3 +188,21 @@ ALTER SOURCE kafka_source SET source_rate_limit TO default;
-- Alter the rate limit of a source to 1000
ALTER SOURCE kafka_source SET source_rate_limit TO 1000;
```

### `SWAP WITH`

```sql
ALTER SOURCE name
SWAP WITH target_name;
```

| Parameter | Description |
| :-------- | :---------- |
| _name_ | The current name of the source to swap. |
| _target_name_ | The target name of the source you want to swap with. |

```sql
-- Swap the names of the api_data source and the file_data source.
ALTER SOURCE api_data
SWAP WITH file_data;
```
30 changes: 30 additions & 0 deletions sql/commands/sql-alter-swap.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
---
title: "ALTER SWAP"
---

The `ALTER ... SWAP` command enables the exchange of names between two database objects, such as tables, materialized views, views, sources, sinks, or subscriptions. It simplifies the process of renaming two objects by allowing them to be swapped in a single operation.

<Note>
The objects being swapped must be of the same type; otherwise, an error will be returned.
</Note>

## Syntax

```sql
ALTER [ TABLE | MATERIALIZED VIEW | VIEW | SOURCE | SINK | SUBSCRIPTION ] name
SWAP WITH target_name;
```

## Parameter

| Parameter | Description |
| :-------- | :---------- |
| _name_ | The current name of the database object to swap. |
| _target_name_ | The target name of the database object you want to swap with. |

## Example

```sql
ALTER MATERIALIZED VIEW historical_sales
SWAP WITH current_sales;
```
20 changes: 19 additions & 1 deletion sql/commands/sql-alter-table.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ ALTER TABLE table_name
alter_option;
```

_`alteroption`_ depends on the operation you want to perform on the table. For all supported clauses, see the sections below.
alter_option depends on the operation you want to perform on the table. For all supported clauses, see the sections below.

## Clauses

Expand Down Expand Up @@ -167,6 +167,24 @@ SELECT fragment_id, parallelism FROM rw_fragments;
(2 rows)
```

### `SWAP WITH`

```sql
ALTER TABLE name
SWAP WITH target_name;
```

| Parameter | Description |
| :-------- | :---------- |
| _name_ | The current name of the table to swap. |
| _target_name_ | The target name of the table you want to swap with. |

```sql
-- Swap the names of the products table and the inventory table.
ALTER TABLE products
SWAP WITH inventory;
```

### `RENAME TO`

```sql
Expand Down
20 changes: 19 additions & 1 deletion sql/commands/sql-alter-view.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ ALTER VIEW view_name
alter_option;
```

_`alteroption`_ depends on the operation you want to perform on the view. For all supported clauses, see the sections below.
`alter_option` depends on the operation you want to perform on the view. For all supported clauses, see the sections below.

## Clause

Expand Down Expand Up @@ -64,3 +64,21 @@ ALTER VIEW view_name
-- Change the name of the view named "view1" to "view2"
ALTER VIEW view1 RENAME TO view2;
```

### `SWAP WITH`

```sql
ALTER VIEW name
SWAP WITH target_name;
```

| Parameter | Description |
| :-------- | :---------- |
| _name_ | The current name of the view to swap. |
| _target_name_ | The target name of the view you want to swap with. |

```sql
-- Swap the names of the user_profiles view and the guest_profiles view.
ALTER VIEW user_profiles
SWAP WITH guest_profiles;
```
Loading