华为云用户手册

  • DISTRIBUTE BY 在ADB中支持分布键,DSC迁移过程中会保留对应分布键。 输入示例 1 2 3 4 5 6 7 CREATE TABLE COPY_DI_DISTRIBUTOR_BUYER_CONTRIBUTION_RANKING_V2 ( SHOP_ID VARCHAR , DISTRIBUTOR_ID VARCHAR , BUYER_ID VARCHAR , DATE_TYPE BIGINT , PRIMARY KEY (SHOP_ID,DISTRIBUTOR_ID,DATE_TYPE,BUYER_ID) ) DISTRIBUTE BY HASH(SHOP_ID,DISTRIBUTOR_ID,DATE_TYPE); 输出示例 1 2 3 4 5 6 7 8 9 10 11 12 CREATE TABLE "public"."copy_di_distributor_buyer_contribution_ranking_v2" ( "shop_id" VARCHAR, "distributor_id" VARCHAR, "buyer_id" VARCHAR, "date_type" BIGINT, PRIMARY KEY ( "shop_id", "distributor_id", "date_type", "buyer_id" ) ) WITH (ORIENTATION = ROW, COMPRESSION = NO) NOCOMPRESS DISTRIBUTE BY HASH (SHOP_ID, DISTRIBUTOR_ID, DATE_TYPE); 父主题: 表(可选参数、操作)
  • DELAY_KEY_WRITE DELAY_KEY_WRITE只对MyISAM引擎表有作用,根据DELAY_KEY_WRITE的值来延迟更新直至表关闭。 GaussDB (DWS)不支持该属性修改表定义信息,DSC迁移时会将该属性删除。 输入示例 1 2 3 4 5 6 7 8 CREATE TABLE `public`.`runoob_tbl_test`( `runoob_id` VARCHAR(30), `runoob_title` VARCHAR(100) NOT NULL, `runoob_author` VARCHAR(40) NOT NULL, `submission_date` VARCHAR(30) ) ENGINE=MyISAM, DELAY_KEY_WRITE=0; ALTER TABLE `public`.`runoob_tbl_test6` DELAY_KEY_WRITE=1; 输出示例 1 2 3 4 5 6 7 8 9 10 CREATE TABLE "public"."runoob_tbl_test" ( "runoob_id" VARCHAR(120), "runoob_title" VARCHAR(400) NOT NULL, "runoob_author" VARCHAR(160) NOT NULL, "submission_date" VARCHAR(120) ) WITH ( ORIENTATION = ROW, COMPRESSION = NO ) NOCOMPRESS DISTRIBUTE BY HASH ("runoob_id"); 父主题: 表(可选参数、操作)
  • CONNECTION GaussDB(DWS)不支持该属性修改表定义信息,DSC迁移时会将该属性删除。 CONNECTION关键字在MySQL中用作引用外部数据源。工具暂不支持该特性的完整迁移。基于当前的临时方案,工具仅仅移除该关键字。 输入示例 1 2 3 4 5 6 7 8 9 10 CREATE TABLE `public`.`runoob_alter_test`( `dataType1` int NOT NULL AUTO_INCREMENT, `dataType2` DOUBLE(20,8), `dataType3` TEXT NOT NULL, `dataType4` YEAR NOT NULL DEFAULT '2018', PRIMARY KEY(`dataType1`) ); ALTER TABLE runoob_alter_test CONNECTION 'hello'; ALTER TABLE runoob_alter_test CONNECTION='hello'; 输出示例 1 2 3 4 5 6 7 8 9 10 11 CREATE TABLE "public"."runoob_alter_test" ( "datatype1" SERIAL NOT NULL, "datatype2" DOUBLE PRECISION, "datatype3" TEXT NOT NULL, "datatype4" SMALLINT NOT NULL DEFAULT '2018', PRIMARY KEY ("datatype1") ) WITH ( ORIENTATION = ROW, COMPRESSION = NO ) NOCOMPRESS DISTRIBUTE BY HASH ("datatype1"); 父主题: 表(可选参数、操作)
  • COMMENT 在MySQL中,COMMENT对表进行注释。GaussDB(DWS)支持该属性修改表定义信息,DSC工具迁移时会添加额外的表属性信息。 输入示例 1 2 3 4 5 6 7 8 CREATE TABLE `public`.`runoob_alter_test`( `dataType1` int NOT NULL AUTO_INCREMENT, `dataType2` FLOAT(10,2) COMMENT 'dataType2列', PRIMARY KEY(`dataType1`) ) comment='表的注释'; ALTER TABLE `public`.`runoob_alter_test` COMMENT '修改后的表的注释'; ALTER TABLE `public`.`runoob_alter_test` ADD INDEX age_index(dataType2) COMMENT '索引'; 输出示例 1 2 3 4 5 6 7 8 9 10 11 12 CREATE TABLE "public"."runoob_alter_test" ( "datatype1" SERIAL NOT NULL, "datatype2" REAL COMMENT 'dataType2列', PRIMARY KEY ("datatype1") ) WITH ( ORIENTATION = ROW, COMPRESSION = NO ) NOCOMPRESS DISTRIBUTE BY HASH ("datatype1") COMMENT '表的注释'; ALTER TABLE "public"."runoob_alter_test" COMMENT '修改后的表的注释'; CREATE INDEX "age_index" ON "public"."runoob_alter_test" ("dataType2") COMMENT '索引'; 父主题: 表(可选参数、操作)
  • COLLATE 在MySQL中,COLLATE表示默认的数据库排序规则。GaussDB(DWS)不支持该属性修改表定义信息,DSC迁移时会将该关键字删除。 输入示例 1 2 3 4 5 6 7 8 CREATE TABLE `public`.`runoob_tbl_test`( `runoob_id` VARCHAR(30), `runoob_title` VARCHAR(100) NOT NULL, `runoob_author` VARCHAR(40) NOT NULL, `submission_date` VARCHAR(30) ) COLLATE=utf8_general_ci; ALTER TABLE `public`.`runoob_tbl_test` COLLATE=utf8mb4_bin; 输出示例 1 2 3 4 5 6 7 8 9 10 CREATE TABLE "public"."runoob_tbl_test" ( "runoob_id" VARCHAR(120), "runoob_title" VARCHAR(400) NOT NULL, "runoob_author" VARCHAR(160) NOT NULL, "submission_date" VARCHAR(120) ) WITH ( ORIENTATION = ROW, COMPRESSION = NO ) NOCOMPRESS DISTRIBUTE BY HASH ("runoob_id"); 父主题: 表(可选参数、操作)
  • CLUSTERED KEY 在ADB中,CLUSTERED KEY:聚集索引,定义表中的排序列,聚集索引中键值的逻辑顺序决定了表中相应行的物理顺序。GaussDB(DWS)不支持该属性修改表定义信息,DSC迁移时会将该关键字删除。 输入示例 1 2 3 4 5 6 DROP TABLE IF EXISTS unsupport_parse_test; CREATE TABLE `unsupport_parse_test` ( `username` int, clustered key clustered_key(shopid ASC, datetype ASC) ); DROP TABLE IF EXISTS unsupport_parse_test; 输出示例 1 2 3 4 5 DROP TABLE IF EXISTS "public"."unsupport_parse_test"; CREATE TABLE "public"."unsupport_parse_test" ( "username" INTEGER ) WITH (ORIENTATION = ROW, COMPRESSION = NO) NOCOMPRESS DISTRIBUTE BY HASH ("username"); DROP TABLE IF EXISTS "public"."unsupport_parse_test"; 父主题: 表(可选参数、操作)
  • AVG_ROW_LENGTH 在MySQL中,AVG_ROW_LENGTH表示平均每行的长度。 GaussDB(DWS)不支持此属性,并在迁移过程中被DSC删除。 输入示例 1 2 3 4 5 6 CREATE TABLE `public`.`runoob_tbl_test`( `runoob_id` VARCHAR(30), `runoob_title` VARCHAR(100) NOT NULL, `runoob_author` VARCHAR(40) NOT NULL, `submission_date` VARCHAR(30) )AVG_ROW_LENGTH=10000; 输出示例 1 2 3 4 5 6 7 8 9 10 CREATE TABLE "public"."runoob_tbl_test" ( "runoob_id" VARCHAR(120), "runoob_title" VARCHAR(400) NOT NULL, "runoob_author" VARCHAR(160) NOT NULL, "submission_date" VARCHAR(120) ) WITH ( ORIENTATION = ROW, COMPRESSION = NO ) NOCOMPRESS DISTRIBUTE BY HASH ("runoob_id"); 父主题: 表(可选参数、操作)
  • AUTO_INCREMENT 在数据库应用中,我们经常需要用到自动递增的唯一编号来标识记录。在MySQL中,可通过数据列的auto_increment属性来自动生成。可在建表时可用“auto_increment=n”选项来指定一个自增的初始值。可用“alter table table_name auto_increment=n”命令来重设自增的起始值。GaussDB(DWS)不支持该参数,DSC迁移时会将设置该属性的字段迁移为SERIAL类型,并删除该关键字,转换如下表。 表1 数据类型转换 MySQL数字类型 MySQL INPUT GaussDB(DWS) OUTPUT TINYINT TINYINT SMALLSERIAL SMALLINT SMALLINT UNSIGNED SMALLINT SERIAL SMALLSERIAL DOUBLE/FLOAT DOUBLE/FLOAT BIGSERIAL INT/INTEGER INT/INTEGER UNSIGNED INT/INTEGER BIGSERIAL SERIAL BIGINT/SERIAL BIGINT/SERIAL BIGSERIAL 输入示例 1 2 3 4 5 CREATE TABLE `public`.`job_instance` ( `job_sche_id` int(11) NOT NULL AUTO_INCREMENT, `task_name` varchar(100) NOT NULL DEFAULT '', PRIMARY KEY (`job_sche_id`) ) ENGINE=InnoDB AUTO_INCREMENT=219 DEFAULT CHARSET=utf8; 输出示例 1 2 3 4 5 6 7 8 9 CREATE TABLE "public"."job_instance" ( "job_sche_id" SERIAL NOT NULL, "task_name" VARCHAR(400) NOT NULL DEFAULT '', PRIMARY KEY ("job_sche_id") ) WITH ( ORIENTATION = ROW, COMPRESSION = NO ) NOCOMPRESS DISTRIBUTE BY HASH ("job_sche_id"); 此外,GaussDB(DWS)也不支持基于AUTO_INCREMENT属性修改表定义信息。DSC迁移时会将其移除。 输入示例 1 2 3 4 5 6 7 8 CREATE TABLE IF NOT EXISTS `public`.`runoob_alter_test`( `dataType1` int NOT NULL AUTO_INCREMENT, `dataType2` FLOAT(10,2), PRIMARY KEY(`dataType1`) ); ALTER TABLE runoob_alter_test AUTO_INCREMENT 100; ALTER TABLE runoob_alter_test AUTO_INCREMENT=100; 输出示例 1 2 3 4 5 6 7 8 9 CREATE TABLE IF NOT EXISTS "public"."runoob_alter_test" ( "datatype1" SERIAL NOT NULL, "datatype2" REAL, PRIMARY KEY ("datatype1") ) WITH ( ORIENTATION = ROW, COMPRESSION = NO ) NOCOMPRESS DISTRIBUTE BY HASH ("datatype1"); 父主题: 表(可选参数、操作)
  • ALTER TABLE RENAME GaussDB(DWS)不支持rename子句包含schema名,因此DSC工具只支持同schema下的rename。同schema下rename,转换结果去掉子句schema,跨schema的rename报错。 输入示例 1 2 3 4 ALTER TABLE `shce1`.`t1` rename to `t2`; ALTER TABLE `shce1`.`t1` rename to t2; ALTER TABLE `charge_data`.`group_shengfen2022` RENAME `charge_data`.`group_shengfen2022_jiu`; ALTER TABLE `charge_data`.`group_shengfen2022` RENAME `charge_data`.`group_shengfen2022_jiu`, RENAME `charge_data`.`group_shengfen2023_jiu`, RENAME `charge_data`.`group_shengfen2024_jiu`; 输出示例 1 2 3 4 ALTER TABLE "shce1"."t1" RENAME TO "t2"; ALTER TABLE "shce1"."t1" RENAME TO "t2"; ALTER TABLE "charge_data"."group_shengfen2022" RENAME TO "group_shengfen2022_jiu"; ALTER TABLE "charge_data"."group_shengfen2022" RENAME TO "group_shengfen2022_jiu", RENAME TO "group_shengfen2023_jiu", RENAME TO "group_shengfen2024_jiu"; 父主题: 表(可选参数、操作)
  • ALGORITHM MySQL扩展了对ALTER TABLE … ALGORITHM=INSTANT的支持:用户可以在表的任何位置即时添加列、即时删除列、添加列时评估行大小限制。 GaussDB(DWS)不支持此属性,并在迁移过程中被DSC删除。 输入示例 1 2 3 4 5 6 7 8 9 ALTER TABLE runoob_alter_test ALGORITHM=DEFAULT; ALTER TABLE runoob_alter_test ALGORITHM=INPLACE; ALTER TABLE runoob_alter_test ALGORITHM=COPY; ALTER TABLE runoob_alter_test ADD COLUMN COL_18 VARCHAR(64) DEFAULT '00', ALGORITHM=INSTANT; ALTER TABLE runoob_alter_test MODIFY COLUMN dataType7 BIGINT, ALGORITHM=COPY; ALTER TABLE `runoob_alter_test` ALGORITHM=DEFAULT, ALGORITHM=INPLACE, ALGORITHM=COPY; ALTER TABLE `runoob_alter_test` ADD COLUMN dataType11 INT, ALGORITHM=DEFAULT, ALGORITHM=INPLACE, ALGORITHM=COPY; ALTER TABLE runoob_alter_test CHANGE COLUMN dataType11 dataType12 SMALLINT ,ALGORITHM=INPLACE, ALGORITHM=COPY; ALTER TABLE runoob_alter_test ALGORITHM=INPLACE, ALGORITHM=COPY, DROP COLUMN dataType12; 输出示例 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 ALTER TABLE "public"."runoob_alter_test" ADD COLUMN "col_18" VARCHAR(256) DEFAULT '00'; ALTER TABLE "public"."runoob_alter_test" MODIFY "datatype7" BIGINT NULL DEFAULT NULL; ALTER TABLE "public"."runoob_alter_test" ADD COLUMN "datatype11" INTEGER; ALTER TABLE "public"."runoob_alter_test" CHANGE COLUMN "datatype11" "datatype12" SMALLINT NULL DEFAULT NULL; ALTER TABLE "public"."runoob_alter_test" DROP COLUMN "datatype12" RESTRICT; DROP TABLE IF EXISTS "public"."runoob_alter_test"; 父主题: 表(可选参数、操作)
  • 表(可选参数、操作) 本节主要介绍表(可选参数、操作)的迁移语法。迁移语法决定了关键字/功能的迁移方式。GaussDB(DWS)不支持表(可选参数),目前针对表(可选参数)的迁移方法都是临时迁移方法。 ALGORITHM ALTER TABLE RENAME AUTO_INCREMENT AVG_ROW_LENGTH BLOCK_SIZE CHARSET CHECKSUM CLUSTERED KEY COLLATE COMMENT CONNECTION DEFAULT DELAY_KEY_WRITE DISTRIBUTE BY DIRECTORY ENGINE FOREIGN_KEY_CHECKS IF NOT EXISTS INDEX_ALL INSERT_METHOD KEY_BLOCK_SIZE LOCK MAX_ROWS MIN_ROWS PACK_KEYS PARTITION BY PASSWORD ROW_FORMAT STATS_AUTO_RECALC STATS_PERSISTENT STATS_SAMPLE_PAGES UNION WITH AS CHANGE修改列 CHECK约束 DROP删除表 LIKE 表克隆 MODIFY修改列 TRUNCATE 删除表 ROUNDROBIN表 RENAME 重命名表名 设置与清除列默认值 字段名重命名 行列存压缩 添加与删除列 父主题: MySQL语法迁移
  • 类型对照 输入示例JSON 1 2 3 4 5 6 7 CREATE TABLE IF NOT EXISTS `runoob_dataType_test`( `dataType_1` INT, `dataType_2` VARCHAR, `dataType_3` JSON ); ALTER TABLE `runoob_dataType_test` ADD COLUMN `dataType_4` JSON NOT NULL; ALTER TABLE `runoob_dataType_test` CHANGE COLUMN `dataType_4` `dataType_5` JSON NOT NULL; 输出示例 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 CREATE TABLE IF NOT EXISTS "public"."runoob_datatype_test" ( "datatype_1" INTEGER, "datatype_2" VARCHAR, "datatype_3" JSONB ) WITH ( ORIENTATION = ROW, COMPRESSION = NO ) NOCOMPRESS DISTRIBUTE BY HASH ("datatype_1"); ALTER TABLE "public"."runoob_datatype_test" ADD COLUMN "datatype_4" JSONB; ALTER TABLE "public"."runoob_datatype_test" CHANGE COLUMN "datatype_4" "datatype_5" JSONB;
  • 类型对照 表1 集合类型对照表 MySQL集合类型 MySQL INPUT GaussDB(DWS) OUTPUT ENUM ENUM VARCHAR SET SET VARCHAR 对于ENUM的类型转换,将转换为VARCHAR类型,精度大小为枚举值中最长字段长度的4倍,并使用CHECK()函数确保输入枚举值的正确性 对于SET的类型转换,将转换为VARCHAR类型,精度大小为各枚举值字段长度与分隔符数量和的4倍。 输入示例ENUM 1 2 3 4 CREATE TABLE IF NOT EXISTS `runoob_dataType_test`( id int(2) PRIMARY KEY, `dataType_17` ENUM('dws-1', 'dws-2', 'dws-3') ); 输出示例 1 2 3 4 5 6 7 8 CREATE TABLE IF NOT EXISTS "public"."runoob_datatype_test" ( "id" INTEGER(2) PRIMARY KEY, "datatype_17" VARCHAR(20) CHECK (dataType_17 IN('dws-1','dws-2','dws-3','', null)) ) WITH ( ORIENTATION = ROW, COMPRESSION = NO ) NOCOMPRESS DISTRIBUTE BY HASH ("id"); 输入示例SET 1 2 3 CREATE TABLE IF NOT EXISTS `runoob_tbl_test`( `dataType_18` SET('dws-1', 'dws-2', 'dws-3') ); 输出示例 1 2 3 4 5 6 7 CREATE TABLE IF NOT EXISTS "public"."runoob_tbl_test" ( "datatype_18" VARCHAR(68) ) WITH ( ORIENTATION = ROW, COMPRESSION = NO ) NOCOMPRESS DISTRIBUTE BY HASH ("datatype_18");
  • 类型对照 表1 大对象类型对照表 MySQL大对象类型 MySQL INPUT GaussDB(DWS) OUTPUT TINYBLOB TINYBLOB BLOB BLOB BLOB BLOB MEDIUMBLOB MEDIUMBLOB BLOB LONGBLOB LONGBLOB BLOB 输入示例[TINY|MEDIUM|LONG]BLOB 1 2 3 4 5 6 7 CREATE TABLE IF NOT EXISTS `runoob_dataType_test`( `dataType_1` BIGINT, `dataType_2` TINYBLOB, `dataType_3` BLOB, `dataType_4` MEDIUMBLOB, `dataType_5` LONGBLOB ); 输出示例 1 2 3 4 5 6 7 8 9 10 11 CREATE TABLE IF NOT EXISTS "public"."runoob_datatype_test" ( "datatype_1" BIGINT, "datatype_2" BLOB, "datatype_3" BLOB, "datatype_4" BLOB, "datatype_5" BLOB ) WITH ( ORIENTATION = ROW, COMPRESSION = NO ) NOCOMPRESS DISTRIBUTE BY HASH ("datatype_1");
  • 类型对照 表1 空间数据类型对照表 MySQL空间数据类型 MySQL INPUT GaussDB(DWS) OUTPUT GEOMETRY GEOMETRY GEOMETRY POINT POINT POINT LINESTRING LINESTRING POLYGON POLYGON POLYGON POLYGON MULTIPOINT MULTIPOINT BOX MULTILINESTRING MULTILINESTRING BOX MULTIPOLYGON MULTIPOLYGON POLYGON GEOMETRYCOLLECTION GEOMETRYCOLLECTION GEOMETRYCOLLECTION GEOMETRY可以存储任何类型的几何值。其他单值类型(POINT, LINESTRING和POLYGON)将其值限制为特定的几何类型。 GEOMETRYCOLLECTION可以存储任何类型的对象的集合。其他集合类型(MULTIPOINT, MULTILINESTRING, MULTIPOLYGON,和 GEOMETRYCOLLECTION)限制集合成员像那些具有特定的几何形状的类型。 输入示例 1 2 3 4 5 6 7 8 9 10 11 12 13 CREATE TABLE `t_geo_test2` ( `id` int(11) NOT NULL, `name` varchar(255), `geometry_1` geometry NOT NULL, `point_1` point NOT NULL, `linestring_1` linestring NOT NULL, `polygon_1` polygon NOT NULL, `multipoint_1` multipoint NOT NULL, `multilinestring_1` multilinestring NOT NULL, `multipolygon_1` multipolygon NOT NULL, `geometrycollection_1` geometrycollection NOT NULL, PRIMARY KEY (`id`) USING BTREE ) ENGINE = InnoDB; 输出示例 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 CREATE TABLE "public"."t_geo_test2" ( "id" INTEGER(11) NOT NULL, "name" VARCHAR(255), "geometry_1" GEOMETRY NOT NULL, "point_1" POINT NOT NULL, "linestring_1" POLYGON NOT NULL, "polygon_1" POLYGON NOT NULL, "multipoint_1" BOX NOT NULL, "multilinestring_1" BOX NOT NULL, "multipolygon_1" POLYGON NOT NULL, "geometrycollection_1" GEOMETRYCOLLECTION NOT NULL, PRIMARY KEY ("id") ) WITH ( ORIENTATION = ROW, COMPRESSION = NO ) NOCOMPRESS DISTRIBUTE BY HASH ("id");
  • 类型对照 表1 日期和时间类型对照表 MySQL日期时间类型 MySQL INPUT GaussDB(DWS) OUTPUT DATETIME DATETIME[(fsp)] TIMESTAMP[(fsp)] WITHOUT TIME ZONE TIME TIME[(fsp)] TIME[(fsp)] WITHOUT TIME ZONE TIMESTAMP TIMESTAMP[(fsp)] TIMESTAMP[(fsp)] WITH TIME ZONE YEAR YEAR[(4)] SMALLINT(4) 该fsp值如果给出,则必须在0到6的范围内。值为0表示没有小数部分。如果省略,则默认精度为0。 输入示例DATETIME 1 2 3 4 5 6 7 CREATE TABLE IF NOT EXISTS `runoob_dataType_test`( `dataType_1` DATETIME, `dataType_2` DATETIME(0), `dataType_3` DATETIME(6), `dataType_4` DATETIME DEFAULT NULL, `dataType_5` DATETIME DEFAULT '2018-10-12 15:27:33.999999' ); 输出示例 1 2 3 4 5 6 7 8 9 10 11 CREATE TABLE IF NOT EXISTS "public"."runoob_datatype_test" ( "datatype_1" TIMESTAMP WITHOUT TIME ZONE, "datatype_2" TIMESTAMP(0) WITHOUT TIME ZONE, "datatype_3" TIMESTAMP(6) WITHOUT TIME ZONE, "datatype_4" TIMESTAMP WITHOUT TIME ZONE DEFAULT NULL, "datatype_5" TIMESTAMP WITHOUT TIME ZONE DEFAULT '2018-10-12 15:27:33.999999' ) WITH ( ORIENTATION = ROW, COMPRESSION = NO ) NOCOMPRESS DISTRIBUTE BY HASH ("datatype_1"); 输入示例TIME 1 2 3 4 5 6 7 8 9 10 11 CREATE TABLE IF NOT EXISTS `runoob_dataType_test`( `dataType_1` TIME DEFAULT '20:58:10', `dataType_2` TIME(3) DEFAULT '20:58:10', `dataType_3` TIME(6) DEFAULT '20:58:10', `dataType_4` TIME(6) DEFAULT '2018-10-11 20:00:00', `dataType_5` TIME(6) DEFAULT '20:58:10.01234', `dataType_6` TIME(6) DEFAULT '2018-10-11 20:00:00.01234', `dataType_7` TIME DEFAULT NULL, `dataType_8` TIME(6) DEFAULT NULL, PRIMARY KEY (dataType_1) ); 输出示例 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 CREATE TABLE IF NOT EXISTS "public"."runoob_datatype_test" ( "datatype_1" TIME WITHOUT TIME ZONE DEFAULT '20:58:10', "datatype_2" TIME(3) WITHOUT TIME ZONE DEFAULT '20:58:10', "datatype_3" TIME(6) WITHOUT TIME ZONE DEFAULT '20:58:10', "datatype_4" TIME(6) WITHOUT TIME ZONE DEFAULT '2018-10-11 20:00:00', "datatype_5" TIME(6) WITHOUT TIME ZONE DEFAULT '20:58:10.01234', "datatype_6" TIME(6) WITHOUT TIME ZONE DEFAULT '2018-10-11 20:00:00.01234', "datatype_7" TIME WITHOUT TIME ZONE DEFAULT NULL, "datatype_8" TIME(6) WITHOUT TIME ZONE DEFAULT NULL, PRIMARY KEY ("datatype_1") ) WITH ( ORIENTATION = ROW, COMPRESSION = NO ) NOCOMPRESS DISTRIBUTE BY HASH ("datatype_1"); 输入示例TIMESTAMP 1 2 3 4 5 6 7 8 9 CREATE TABLE IF NOT EXISTS `runoob_dataType_test`( `dataType_1` TIMESTAMP, `dateType_4` TIMESTAMP DEFAULT '2018-10-12 15:27:33', `dateType_5` TIMESTAMP DEFAULT '2018-10-12 15:27:33.999999', `dateType_6` TIMESTAMP DEFAULT '2018-10-12 15:27:33', `dateType_7` TIMESTAMP DEFAULT '2018-10-12 15:27:33', `dataType_8` TIMESTAMP(0) DEFAULT '2018-10-12 15:27:33', `dateType_9` TIMESTAMP(6) DEFAULT '2018-10-12 15:27:33' ); 输出示例 1 2 3 4 5 6 7 8 9 10 11 12 13 CREATE TABLE IF NOT EXISTS "public"."runoob_datatype_test" ( "datatype_1" TIMESTAMP WITH TIME ZONE, "datetype_4" TIMESTAMP WITH TIME ZONE DEFAULT '2018-10-12 15:27:33', "datetype_5" TIMESTAMP WITH TIME ZONE DEFAULT '2018-10-12 15:27:33.999999', "datetype_6" TIMESTAMP WITH TIME ZONE DEFAULT '2018-10-12 15:27:33', "datetype_7" TIMESTAMP WITH TIME ZONE DEFAULT '2018-10-12 15:27:33', "datatype_8" TIMESTAMP(0) WITH TIME ZONE DEFAULT '2018-10-12 15:27:33', "datetype_9" TIMESTAMP(6) WITH TIME ZONE DEFAULT '2018-10-12 15:27:33' ) WITH ( ORIENTATION = ROW, COMPRESSION = NO ) NOCOMPRESS DISTRIBUTE BY HASH ("datatype_1"); 输入示例YEAR 1 2 3 4 5 6 CREATE TABLE IF NOT EXISTS `runoob_dataType_test`( `dataType_1` YEAR, `dataType_2` YEAR(4), `dataType_3` YEAR DEFAULT '2018', `dataType_4` TIME DEFAULT NULL ); 输出示例 1 2 3 4 5 6 7 8 9 10 CREATE TABLE IF NOT EXISTS "public"."runoob_datatype_test" ( "datatype_1" SMALLINT, "datatype_2" SMALLINT, "datatype_3" VARCHAR(4) DEFAULT '2018', "datatype_4" TIME WITHOUT TIME ZONE DEFAULT NULL ) WITH ( ORIENTATION = ROW, COMPRESSION = NO ) NOCOMPRESS DISTRIBUTE BY HASH ("datatype_1");
  • 类型对照 表1 数字类型对照表 MySQL数字类型 MySQL INPUT GaussDB(DWS) OUTPUT DEC DEC DEC[(M[,D])] [UNSIGNED] [ZEROFILL] DECIMAL DECIMAL[(M[,D])] DECIMAL DECIMAL[(M[,D])] [UNSIGNED] [ZEROFILL] DECIMAL[(M[,D])] DOUBLE PRECISION DOUBLE PRECISION DOUBLE PRECISION [(M[,D])] [UNSIGNED] [ZEROFILL] DOUBLE PRECISION DOUBLE PRECISION DOUBLE DOUBLE[(M[,D])] [UNSIGNED] [ZEROFILL] DOUBLE PRECISION FIXED FIXED FIXED[(M[,D])] [UNSIGNED] [ZEROFILL] DECIMAL DECIMAL[(M[,D])] FLOAT FLOAT FLOAT [(M[,D])] [UNSIGNED] [ZEROFILL] FLOAT(p) [UNSIGNED] [ZEROFILL] REAL REAL REAL INT INT INT(p) [UNSIGNED] [ZEROFILL] INTEGER INTEGER(p) INTEGER INTEGER INTEGER(p) [UNSIGNED] [ZEROFILL] INTEGER INTEGER(p) MEDIUMINT MEDIUMINT MEDIUMINT(p) [UNSIGNED] [ZEROFILL] INTEGER INTEGER(p) NUMERIC NUMERIC NUMERIC [(M[,D])] [UNSIGNED] [ZEROFILL] DECIMAL DECIMAL[(M[,D])] REAL REAL[(M[,D])] REAL/DOUBLE PRECISION SMALLINT SMALLINT SMALLINT(p) [UNSIGNED] [ZEROFILL] SMALLINT TINYINT TINYINT TINYINT(n) TINYINT(n) ZEROFILL TINYINT(n) UNSIGNED ZEROFILL SMALLINT SMALLINT SMALLINT TINYINT TINYINT类型做转换时,如果存在无符号类型(UNSIGNED)修饰则转换为TINYINT,否则转换为SMALLINT。 REAL类型做转换时,默认转换为DOUBLE PRECISION,如果配置文件(features-mysql.properties)中table.database.realAsFlag标志为true时(默认false),转换为REAL 输入示例TINYINT 1 2 3 4 5 6 7 CREATE TABLE IF NOT EXISTS `runoob_dataType_test`( `dataType_1` TINYINT, `dataType_2` TINYINT(0), `dataType_3` TINYINT(255), `dataType_4` TINYINT(255) UNSIGNED ZEROFILL, `dataType_5` TINYINT(255) ZEROFILL ); 输出示例 1 2 3 4 5 6 7 8 9 10 11 CREATE TABLE IF NOT EXISTS "public"."runoob_datatype_test" ( "datatype_1" SMALLINT, "datatype_2" SMALLINT, "datatype_3" SMALLINT, "datatype_4" TINYINT, "datatype_5" SMALLINT ) WITH ( ORIENTATION = ROW, COMPRESSION = NO ) NOCOMPRESS DISTRIBUTE BY HASH ("datatype_1");
  • 系统视图 DSC将系统视图dbc.columnsV和dbc.IndicesV进行迁移,输出如下结果。 输入: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 SELECT A.ColumnName AS V_COLS ,A.columnname || ' ' ||CASE WHEN columnType in ('CF','CV') THEN CASE WHEN columnType='CV' THEN 'VAR' ELSE '' END||'CHAR('||TRIM(columnlength (INT))|| ') CHARACTER SET LATIN'|| CASE WHEN UpperCaseFlag='N' THEN ' NOT' ELSE '' END || ' CASESPECIFIC' WHEN columnType='DA' THEN 'DATE' WHEN columnType='TS' THEN 'TIMESTAMP(' || TRIM(DecimalFractionalDigits)||')' WHEN columnType='AT' THEN 'TIME('|| TRIM(DecimalFractionalDigits)||')' WHEN columnType='I' THEN 'INTEGER' WHEN columnType='I1' THEN 'BYTEINT' WHEN columnType='I2' THEN 'SMALLINT' WHEN columnType='I8' THEN 'BIGINT' WHEN columnType='D' THEN 'DECIMAL('||TRIM(DecimalTotalDigits)||','||TRIM(DecimalFractionalDigits)||')' ELSE 'Unknown' END||CASE WHEN Nullable='Y' THEN '' ELSE ' NOT NULL' END||'0A'XC AS V_ColT - ,B.ColumnName AS V_PICol FROM dbc.columnsV A LEFT JOIN dbc.IndicesV B ON A.columnName = B.columnName AND B.IndexType IN ('Q','P') AND B.DatabaseName = '${V_TDDLDB}' AND B.tablename='${TARGET_TABLE}' WHERE A.databasename='${V_TDDLDB}' AND A.tablename = '${TARGET_TABLE}' AND A.columnname NOT IN ( 'ETL_JOB_NAME' ,'ETL_TX_DATE' ,'ETL_PROC_DATE' ) ORDER BY A.columnid; 输出: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 DECLARE lv_mig_V_COLS TEXT; lv_mig_V_ColT TEXT; lv_mig_V_PICol TEXT; BEGIN SELECT STRING_AGG(A.ColumnName, ',') , STRING_AGG(A.columnname || ' ' ||CASE WHEN columnType in ('CF','CV') THEN CASE WHEN columnType='CV' THEN 'VAR' ELSE '' END||'CHAR('||TRIM(mig_td_ext.mig_fn_castasint(columnlength))|| ') /*CHARACTER SET LATIN*/'|| CASE WHEN UpperCaseFlag='N' THEN ' NOT' ELSE '' END || ' /*CASESPECIFIC*/' WHEN columnType='DA' THEN 'DATE' WHEN columnType='TS' THEN 'TIMESTAMP(' || TRIM(DecimalFractionalDigits)||')' WHEN columnType='AT' THEN 'TIME('|| TRIM(DecimalFractionalDigits)||')' WHEN columnType='I' THEN 'INTEGER' WHEN columnType='I1' THEN 'BYTEINT' WHEN columnType='I2' THEN 'SMALLINT' WHEN columnType='I8' THEN 'BIGINT' WHEN columnType='D' THEN 'DECIMAL('||TRIM(DecimalTotalDigits)||','||TRIM(DecimalFractionalDigits)||')' ELSE 'Unknown' END||CASE WHEN Nullable='Y' THEN '' ELSE ' NOT NULL' END||E'\x0A', ',') , STRING_AGG(B.ColumnName, ',') INTO lv_mig_V_COLS, lv_mig_V_ColT, lv_mig_V_PICol FROM mig_td_ext.vw_td_dbc_columnsV A LEFT JOIN mig_td_ext.vw_td_dbc_IndicesV B ON A.columnName = B.columnName AND B.IndexType IN ('Q','P') AND B.DatabaseName = 'public' AND B.tablename='emp2' WHERE A.databasename='public' AND A.tablename = 'emp2'; -- ORDER BY A.columnid; END; / 父主题: Teradata语法迁移
  • 以#开头的列名 输入 输出 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 REPLACE VIEW SC.VIEW_1 ( ,col_1 ,#_col_2 ,#_col_3 ) LOCKING TABLE sc.tab FOR AC CES S AS SEL Tgt.col1 ,Tgt.#_col_2 ,Tgt.#_col_3 FROM sc.tab TGT ; 1 2 3 4 5 6 7 8 9 10 11 12 13 14 CREATE OR REPLACE VIEW SC.VIEW_1 ( ,col_1 ,"#_COL_2" ,"#_COL_3" ) /*LOCKING TABLE sc.tab FOR ACCESS */ AS ( SELECT Tgt.col1 ,Tgt."#_COL_2" ,Tgt."#_COL_3" FROM sc.tab TGT ) ;
  • 以YYYYMMDD格式输入的日期 输入 输出 1 2 3 SELECT 1 FROM tb_dt_fmtyyyymmdd WHERE JobName ='${JOB_NAME}' AND TXDATE = ${TX_DATE} - 19000000; SELECT 1 FROM tb_dt_fmtyyyymmdd WHERE JobName ='${JOB_NAME}' AND TXDATE = TO_DATE(${TX_DATE}, 'YYYYMMDD');
  • 以YYYYDDD格式输入日期 输入 输出 1 2 3 4 5 6 7 8 9 10 11 12 REPLACE VIEW SC.VIEW_1 ( col_1 ) LOCKING TABLE sc.tab FOR ACCESS AS SEL --tgt.col_1 is date type CAST( CAST(TGT.col_1 AS DATE FORMAT 'YYYYDDD') AS CHAR(7) ) AS col_1 FROM sc.tab TGT ; 1 2 3 4 5 6 7 8 9 10 CREATE OR REPLACE VIEW SC.VIEW_1 (col_1) /*LOCKING TABLE sc.tab FOR ACCESS */ AS ( SELECT /* tgt.col_1 is date type */ CAST( TO_DATE(TGT.col_1, 'YYYYDDD') AS CHAR( 7 ) ) AS col_1 FROM sc.tab TGT ) ;
  • 类型转换时优先执行数据库操作 输入 输出 1 2 3 4 5 6 7 8 9 10 11 REPLACE VIEW SC.VIEW_1 ( col_1 ) LOCKING TABLE sc.tab FOR ACCESS AS SEL (COALESCE(TRIM(TGT.col_1),'')) || '_' || (COALESCE(TRIM(TGT.col_1),'')) (CHAR(22)) AS col_1 FROM sc.tab TGT ; 1 2 3 4 5 6 7 8 9 10 11 CREATE OR REPLACE VIEW SC.VIEW_1 (col_1) /*LOCKING TABLE sc.tab FOR ACCESS */ AS ( SELECT CAST( ( COALESCE( TRIM( TGT.col_1 ) ,'' ) ) || '_' || ( COALESCE( TRIM( TGT.col_1 ) ,'' ) ) AS CHAR( 22 ) ) AS col_1 FROM sc.tab TGT ) ;
  • MERGE MERGE是ANSI标准的SQL语法操作符,用于从一个或多个来源中选择行来更新或插入到表或视图中,可以指定更新或插入到目标表或视图的条件。 输入:MERGE 1 2 3 4 5 6 7 8 MERGE INTO tab1 A using ( SELECT c1, c2, ... FROM tab2 WHERE ...) AS B ON A.c1 = B.c1 WHEN MATCHED THEN UPDATE SET c2 = c2 , c3 = c3 WHEN NOT MATCHED THEN INSERT VALUES (B.c1, B.c2, B.c3); 输出 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 WITH B AS ( SELECT c1 ,c2 ,... FROM tab2 WHERE ... ) ,UPD_REC AS ( UPDATE tab1 A SET c2 = c2 ,c3 = c3 FROM B WHERE A.c1 = B.c1 returning A. * ) INSERT INTO tab1 SELECT B.c1 ,B.c2 ,B.c3 FROM B WHERE NOT EXISTS ( SELECT 1 FROM UPD_REC A WHERE A.c1 = B.c1 ) ; 父主题: 数据操作语句(DML)
  • COMMENT语句 COMMENT语句的迁移过程如下所示,输入一个复杂语句,迁移之后语句更加简化。 输入: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 CREATE MULTISET TABLE PDAT.t_tbl_comment ( Data_Dt DATE NOT NULL ,Data_Src VARCHAR(4) NOT NULL ,List_Make_Stat CHAR(1) ) PRIMARY INDEX(Data_Dt,Data_Src) ; COMMENT ON PDAT.t_tbl_comment IS 'comment test on table'; --------------- REPLACE VIEW PVW.v_vw_comment AS LOCKING ROW FOR ACCESS SELECT Data_Dt, Data_Src, List_Make_Stat FROM PDAT.t_tbl_comment; COMMENT ON PVW.v_vw_comment IS 'comment test on view'; COMMENT ON PVW.v_vw_comment.Data_Dt IS 'comment test on view column'; 输出: COMMENT ON TABLE PDAT.t_tbl_comment IS 'comment test on table'; COMMENT ON VIEW PVW.v_vw_comment IS 'comment test on view'; COMMENT ON COLUMN PVW.v_vw_comment.Data_Dt IS 'comment test on view column'; 父主题: Teradata语法迁移
  • SHOW STATS VALUES SEQUENCED 该命令显示COLLECT STATIS TICS 语句的结果以及相关统计信息,且Gauss无对应命令。考虑到该命令不影响功能,因此迁移时可直接注释掉。 输入: SHOW STATS VALUES SEQUENCED on "temp"."table" 输出: /*SHOW STATS VALUES SEQUENCED on "temp"."table"*/ 父主题: Teradata语法迁移
  • dbc.sessioninfoV 输入: select username,clientsystemuserid,clientipaddress,clientprogramname from dbc.sessioninfoV where sessionno = 140167641814784; 输出: select usename AS username, NULL::TEXT AS clientsystemuserid , client_addr AS clientipaddress, application_name AS clientprogramname from pg_catalog.pg_stat_activity WHERE pid = 140167641814784;
  • dbc.sessioninfo 输入: SELECT username ,clientsystemuserid ,clientipaddress ,clientprogramname FROM dbc.sessioninfo WHERE sessionno = lv_mig_session ; 输出: select usename AS username, NULL::TEXT AS clientsystemuserid , client_addr AS clientipaddress, application_name AS clientprogramname from pg_catalog.pg_stat_activity WHERE pid = lv_mig_session;
  • DBC.COLUMNS DBC.COLUMNS视图是一个表,包含有关表和视图列、存储过程、或宏参数的信息。其中包括以下列:DatabaseName、TableName、ColumnName、ColumnFormat、ColumnTitle、ColumnType、DefaultValue。在GaussDB(DWS)中,这个表等效于information_schema.columns表。 本特性要求一次性执行以下自定义脚本文件:DSC/scripts/teradata/db_scripts/mig_fn_get_datatype_short_name.sql 有关文件执行的详细步骤,请参见运行环境和前提条件。 迁移工具将以下dbc.columns列迁移为对应的information_schema列: 表1 dbc.columns列迁移到information_schema列 dbc.columns information_schema.columns ColumnName Column_Name ColumnType mig_fn_get_datatype_short_name (data_Type) ColumnLength character_maximum_length DecimalTotalDigits numeric_precision DecimalFractionalDigits numeric_scale databasename table_schema tablename table_name ColumnId ordinal_position 迁移dbc.columns时,假设以下条件成立: FROM子句仅包含dbc.columns的TABLE NAME。 COLUMN NAME为以下任一格式:column_name或schema_name.table_name.column_name。 以下场景不支持dbc.columns迁移: FROM子句包含dbc.columns表名的别名(dbc.columns别名)。 dbc.columns与其他表组合(FROM dbc.columns alias1,table1 alias2 OR dbc.columns alias1 join table1 alias2)。 如果输入的SELECT语句直接包含dbc.columns的列名,则该工具会将输入的列名称迁移为别名。例如,输入列名称DecimalFractionalDigits会迁移为numeric_scale,其别名为DecimalFractionalDigits。 示例: 输入: 1 2 3 4 5 6 SEL columnid ,DecimalFractionalDigits FROM dbc.columns ; 输出: 1 2 3 4 5 6 SELECT ordinal_position columnid ,numeric_scale DecimalFractionalDigits FROM information_schema.columns ; 关于表名和模式名称,迁移工具会将所有字符串值转换为小写。如果要区分大小写,使用双引号表示表/模式名称。在以下输入示例中,“Test”不会转换为小写。 1 2 3 4 5 6 SELECT TableName FROM dbc . columns WHERE dbc.columns.databasename = '"Test"'; 输入:dbc.columns table,指定所有支持列 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 SELECT '$AUTO_DB_IP' ,objectdatabasename ,objecttablename ,'$TX_DATE_10' ,'' ,'0' ,FirstStepTime ,FirstRespTime ,RowCount ,cast(RowCount*sum(case when T2.ColumnType ='CV' then T2.ColumnLength/3 else T2.ColumnLength end) as decimal(38,0)) ,'3' ,'' ,'BAK_CLR_DATA' ,'2' ,'' FROM TMP_clr_information T1 inner join dbc.columns T2 on T1.objectdatabasename =T2.DatabaseName and T1.objecttablename =T2.TableName where T2.DatabaseName not in ( sel child from dbc.children where parent='$FCRM_DB' ) group by 1,2,3,4,5,6,7,8,9,11,12,13,14,15; 输出: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 SELECT '$AUTO_DB_IP' ,objectdatabasename ,objecttablename ,'$TX_DATE_10' ,'' ,'0' ,FirstStepTime ,FirstRespTime ,RowCount ,CAST( RowCount * SUM ( CASE WHEN mig_fn_get_datatype_short_name ( T2.data_Type ) = 'CV' THEN T2.character_maximum_length / 3 ELSE T2.character_maximum_length END ) AS DECIMAL( 38 ,0 ) ) ,'3' ,'' ,'BAK_CLR_DATA' ,'2' ,'' FROM TMP_clr_information T1 INNER JOIN information_schema.columns T2 ON T1.objectdatabasename = T2.table_schema AND T1.objecttablename = T2.table_name WHERE NOT EXISTS ( SELECT child FROM dbc.children WHERE child = T2.table_schema AND( parent = '$FCRM_DB' ) ) GROUP BY 1 ,2 ,3 ,4 ,5 ,6 ,7 ,8 ,9 ,11 ,12 ,13 ,14 ,15 ; 输入:dbc.columns table,指定表名 1 2 3 4 5 6 7 8 9 10 SELECT TRIM( ColumnName ) ,UPPER( dbc.columns.ColumnType ) FROM dbc . columns WHERE dbc.columns.databasename = '"Test"' ORDER BY dbc.columns.ColumnId ; 输出: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 SELECT TRIM( Column_Name ) ,UPPER( mig_fn_get_datatype_short_name ( information_schema.columns.data_Type ) ) FROM information_schema.columns WHERE information_schema.columns.table_schema = CASE WHEN TRIM( '"Test"' ) LIKE '"%' THEN REPLACE( SUBSTR( '"Test"' ,2 ,LENGTH( '"Test"' ) - 2 ) ,'""' ,'"' ) ELSE LOWER( '"Test"' ) END ORDER BY information_schema.columns.ordinal_position ; 父主题: Teradata语法迁移
  • ACCESS LOCK ACCESS LOCK允许用户从可能已经锁定READ或WRITE的表中读取数据。 可以通过tdMigrateLOCKoption参数来配置如何对包含LOCK关键字的查询进行迁移。如果该参数设置为false,工具将跳过该查询的迁移并记录日志。 输入:ACCESS LOCK(tdMigrateLOCKOption=True) 1 2 3 4 5 LOCKING TABLE tab1 FOR ACCESS INSERT INTO tab2 SELECT … FROM … WHERE ...; 输出: 1 2 3 4 5 /* LOCKING TABLE tab1 FOR ACCESS */ INSERT INTO tab2 SELECT … FROM … WHERE ...; 父主题: Teradata语法迁移
  • REPLACE FUNCTION 输入: REPLACE FUNCTION up_load1.RPT_016_BUS_DATE() RETURNS DATE LANGUAGE SQL CONTAINS SQL DETERMINISTIC SQL SECURITY DEFINER COLLATION INVOKER INLINE TYPE 1 RETURN DATE'2017-08-22'; 输出: CREATE OR REPLACE FUNCTION up_load1.RPT_016_BUS_DATE() RETURNS DATE LANGUAGE SQL IMMUTABLE SECURITY DEFINER AS $$ SELECT CAST('2017-08-20' AS DATE) $$ ;
共100000条