Skip to content

Conversation

TCeason
Copy link
Collaborator

@TCeason TCeason commented Sep 23, 2025

I hereby agree to the terms of the CLA available at: https://docs.databend.com/dev/policies/cla/

Summary

Syntax

ALTER TABLE [IF EXISTS] <source_table_name> SWAP WITH <target_table_name>;

Caution

  1. Engine Support: Only available for Fuse Engine tables.
  2. Table Type: Temporary tables are not supported for swapping.
  3. Permissions: The operation can only be executed by:
    The current role is the owner of both tables.
  4. Database Scope: Swapping is limited to tables within the same database.

Example

CREATE OR REPLACE TABLE t1(a1 int, a2 VARCHAR, a3 DATE)
CREATE OR REPLACE TABLE t2(b1 VARCHAR)
desc t1
╭──────────────────────────────────────────────╮
│  Field │   Type  │  Null  │ Default │  Extra │
│ String │  String │ String │  String │ String │
├────────┼─────────┼────────┼─────────┼────────┤
│ a1     │ INT     │ YES    │ NULL    │        │
│ a2     │ VARCHAR │ YES    │ NULL    │        │
│ a3     │ DATE    │ YES    │ NULL    │        │
╰──────────────────────────────────────────────╯
desc t2

╭──────────────────────────────────────────────╮
│  Field │   Type  │  Null  │ Default │  Extra │
│ String │  String │ String │  String │ String │
├────────┼─────────┼────────┼─────────┼────────┤
│ b1     │ VARCHAR │ YES    │ NULL    │        │
╰──────────────────────────────────────────────╯

Swap table

ALTER TABLE t1 SWAP WITH t2

desc t1

╭──────────────────────────────────────────────╮
│  Field │   Type  │  Null  │ Default │  Extra │
│ String │  String │ String │  String │ String │
├────────┼─────────┼────────┼─────────┼────────┤
│ b1     │ VARCHAR │ YES    │ NULL    │        │
╰──────────────────────────────────────────────╯

desc t2

╭──────────────────────────────────────────────╮
│  Field │   Type  │  Null  │ Default │  Extra │
│ String │  String │ String │  String │ String │
├────────┼─────────┼────────┼─────────┼────────┤
│ a1     │ INT     │ YES    │ NULL    │        │
│ a2     │ VARCHAR │ YES    │ NULL    │        │
│ a3     │ DATE    │ YES    │ NULL    │        │
╰──────────────────────────────────────────────╯

Tests

  • Unit Test
  • Logic Test
  • Benchmark Test
  • No Test - Explain why

Type of change

  • Bug Fix (non-breaking change which fixes an issue)
  • New Feature (non-breaking change which adds functionality)
  • Breaking Change (fix or feature that could cause existing functionality not to work as expected)
  • Documentation Update
  • Refactoring
  • Performance Improvement
  • Other (please describe):

This change is Reviewable

@TCeason TCeason marked this pull request as draft September 23, 2025 14:00
@github-actions github-actions bot added the pr-feature this PR introduces a new feature to the codebase label Sep 23, 2025
@TCeason TCeason marked this pull request as ready for review September 23, 2025 15:06
Copy link
Member

@drmingdrmer drmingdrmer left a comment

Choose a reason for hiding this comment

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

@drmingdrmer reviewed 7 of 31 files at r1, all commit messages.
Reviewable status: 7 of 31 files reviewed, all discussions resolved (waiting on @dantengsky and @SkyFan2002)

@TCeason TCeason merged commit 4085be4 into databendlabs:main Sep 26, 2025
87 of 88 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pr-feature this PR introduces a new feature to the codebase
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Feature: enable swap between tables
4 participants