Note:
This topic has been translated from a Chinese forum by GPT and might contain errors.
Original topic: 假如要自己实现create table as 语法支持
[Overview] The Oracle syntax “create table as select * from a” is very convenient and was often used for table backups. How can this syntax be implemented in TiDB?
Off-topic:
This syntax in MySQL is very inconvenient; DDL and DML are not good statements to combine.
By implementing database file copying and renaming at the underlying level, and adding information in the metadata, it can be achieved quickly and without errors. Of course, this is suitable for full replication.
It’s unrealistic. How do you copy with conditions?
First, create table like, then BATCH into to see if it can solve your problem.
Basically unrealistic, better wait for native support.
Not considering ease of use, it doesn’t seem very difficult to implement.
It’s better to export with dumpling, then create table like, and finally import with lightning. The efficiency of batch non-transactional statements is still relatively poor.
You can create the table first, and then use insert into select *
Sure, please provide the text you need translated from Chinese to English.
This operation is rather cumbersome.
It is a bit cumbersome, but the execution efficiency is much higher than batch on, batch on is too slow.
It seems we still need to take a two-step approach.
CREATE TABLE new_table AS SELECT column1, column2, function(column3) AS new_column FROM old_table WHERE condition;
Create a table, then insert into select * from …
You can only create table; then perform insert into select.
Create the table first, then insert.