How to replicate data in a TiDB table?

Note:
This topic has been translated from a Chinese forum by GPT and might contain errors.

Original topic: tidb 复制表中的数据如何复制?

| username: 烂番薯0

TiDB v6.5.0 does not support the syntax “create table table_name as select * from T”. However, if I only want a specific segment of data from table T, such as “create table table_name as select * from T where T.pk > 2000 and T.pk < 2500 and T.cust_name IN (‘tom’, ‘jack’, ‘eason’);”, how should I do it?

| username: tidb菜鸟一只 | Original post link

show create table T;
Then change the table name in the original create table statement to table_name,
Then insert into table_name select * from T where T.pk > 2000 and T.pk < 2500 and T.cust_name IN (‘tom’, ‘jack’, ‘eason’);

| username: 烂番薯0 | Original post link

Thank you, boss.

| username: zhanggame1 | Original post link

Divided into two steps:
create table XXXX like XXXX;
insert into select * from XXXX where …

Note that there is a 1G memory data import limit. For example, you can change it to 8G in the execution window by setting tidb_mem_quota_query=8589934592.

| username: 烂番薯0 | Original post link

Thank you, thank you, boss.

| username: wangccsy | Original post link

Use the Insert Select syntax. If the two tables are the same, use it directly. If column names need to correspond, specify the column names.

| username: dba远航 | Original post link

create table new_tab like t;
insert into new_tab select * from T where T.pk > 2000 and T.pk < 2500 and T.cust_name IN ('tom', 'jack', 'eason');
| username: 哈喽沃德 | Original post link

If it doesn’t support one step, then take two steps: first create the table, then insert.

| username: kelvin | Original post link

First create, then insert.

| username: xingzhenxiang | Original post link

TiDB has maximum transaction control. This approach works for small tables, but you need to be cautious with large tables.

| username: system | Original post link

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.