Updated on 2024-05-31 GMT+08:00

DML

No.

Description

Syntax

Difference

1

DELETE supports deleting data from multiple tables.

DELETE

-

2

DELETE supports ORDER BY and LIMIT.

DELETE

-

3

DELETE supports deleting data from a specified partition (or subpartition).

DELETE

-

4

UPDATE supports updating data from multiple tables.

UPDATE

-

5

UPDATE supports ORDER BY and LIMIT.

UPDATE

-

6

The syntax is compatible with SELECT INTO.

SELECT

  • In GaussDB, you can use SELECT INTO to create a table based on the query result. MySQL does not support this function.
  • In GaussDB, the SELECT INTO syntax does not support the query result that is obtained after the set operation of multiple queries is performed.

7

The syntax is compatible with REPLACE INTO.

REPLACE

  • Difference between the initial values of the time type. For example:
    • MySQL is not affected by the strict or loose mode. You can insert time 0 into a table.
      mysql> CREATE TABLE test(f1 TIMESTAMP NOT NULL, f2 DATETIME NOT NULL, f3 DATE NOT NULL);
      Query OK, 1 row affected (0.00 sec)
      
      mysql> REPLACE INTO test VALUES(f1, f2, f3);
      Query OK, 1 row affected (0.00 sec)
      
      mysql> SELECT * FROM test;
      +---------------------+---------------------+------------+
      | f1                  | f2                  | f3         |
      +---------------------+---------------------+------------+
      | 0000-00-00 00:00:00 | 0000-00-00 00:00:00 | 0000-00-00 |
      +---------------------+---------------------+------------+
      1 row in set (0.00 sec)
    • The time 0 can be successfully inserted only when GaussDB is in loose mode.
      gaussdb=# SET b_format_version = '5.7';
      SET
      gaussdb=# SET b_format_dev_version = 's1';
      SET
      gaussdb=# SET sql_mode = '';
      SET
      gaussdb=# CREATE TABLE test(f1 TIMESTAMP NOT NULL, f2 DATETIME NOT NULL, f3 DATE NOT NULL);
      CREATE TABLE
      gaussdb=# REPLACE INTO test VALUES(f1, f2, f3);
      REPLACE 0 1
      gaussdb=# SELECT * FROM test;
      f1          |         f2          |     f3
      ---------------------+---------------------+------------
      0000-00-00 00:00:00 | 0000-00-00 00:00:00 | 0000-00-00
      (1 row)

      In strict mode, the error is reported: date/time field value out of range: "0000-00-00 00:00:00".

  • Difference between the initial values of the bit string type. For example:
    • The initial value of the MySQLBIT type is an empty string '', and the length is M/8 (rounded up), that is:
      mysql> CREATE TABLE test(f1 BIT(3) NOT NULL);
      Query OK, 0 rows affected (0.01 sec)
      
      mysql> REPLACE INTO test VALUES(f1);
      Query OK, 1 row affected (0.00 sec)
      
      mysql> SELECT f1, length(f1) FROM test;
      +----+------------+
      | f1 | length(f1) |
      +----+------------+
      |    |          1 |
      +----+------------+
      1 row in set (0.00 sec)
    • In GaussDB, if the initial value of the BIT type is an empty string '' and the length is 0, an error is reported.
      gaussdb=# CREATE TABLE test(f1 BIT(3) NOT NULL);
      CREATE TABLE
      gaussdb=# REPLACE INTO test VALUES(f1);
      REPLACE 0 1
      gaussdb=# 
      SELECT f1, length(f1) FROM test;
      +----+------------+
      | f1 | length(f1) |
      +----+------------+
      |    |          0 |
      +----+------------+
      (1 row)

8

SELECT supports multi-partition query.

SELECT

-

9

UPDATE supports multi-partition update.

UPDATE

-

10

Import data by using LOAD DATA.

LOAD DATA

When LOAD DATA is used to import data, GaussDB differs from MySQL in the following aspects:

  • The execution result of the LOAD DATA syntax is the same as that in M* strict mode. The loose mode is not adapted currently.
  • The IGNORE and LOCAL parameters are used only to ignore the conflicting rows when the imported data conflicts with the data in the table and to automatically fill default values for other columns when the number of columns in the file is less than that in the table. Other functions are not supported currently.
  • If the keyword LOCAL is specified and the file path is a relative path, the file is searched from the binary directory. If the keyword LOCAL is not specified and the file path is a relative path, the file is searched from the data directory.
  • If single quotation marks are specified as separators, escape characters, and line breaks in the syntax, lexical parsing errors occur.
  • The [(col_name_or_user_var [, col_name_or_user_var]...)] parameter cannot be used to specify a column repeatedly.
  • The newline character specified by [FIELDS TERMINATED BY 'string'] cannot be the same as the separator specified by [LINES TERMINATED BY'string'].
  • If the data written to a table by running LOAD DATA cannot be converted to the data type of the table, an error is reported.
  • The LOAD DATA SET expression does not support the calculation of a specified column name.
  • If there is no implicit conversion function between the return value type of the SET expression and the corresponding column type, an error is reported.
  • LOAD DATA applies only to tables but not views.
  • The default newline character of the file in Windows is different from that in Linux. LOAD DATA cannot identify this scenario and reports an error. You are advised to check the newline character at the end of lines of the file to be imported.

11

INSERT supports the VALUES reference column syntax.

INSERT INTO tabname VALUES(1,2,3) ON DUPLICATE KEY UPDATE b = VALUES(column_name)

The format of table-name.column-name is not supported by VALUES() in the ON DUPLICATE KEY UPDATE clause in GaussDB, but is supported in MySQL.

12

LIMIT differences

DELETE, SELECT, and UPDATE

The LIMIT clauses of each statement in GaussDB are different from those in MySQL.

The maximum parameter value of LIMIT (of the BIG INT type) in GaussDB is 9223372036854775807. If the actual value exceeds the number, an error is reported. In MySQL, the maximum value of LIMIT (of the unsigned LONGLONG type) is 18446744073709551615. If the actual value exceeds the number, an error is reported.

You can set a small value in LIMIT, which is rounded off during execution. The value cannot be a decimal in MySQL.

In a DELETE statement, GaussDB does not allow limit to be 0, while MySQL allows limit to be 0.

13

Difference in using backslashes (\)

INSERT

The usage of backslashes (\) can be determined by parameters in GaussDB and MySQL, but their default usages are different.

In MySQL, the NO_BACKSLASH_ESCAPES parameter is used to determine whether backslashes (\) in character strings and identifiers are parsed as common characters or escape characters. By default, backslashes (\) are parsed as escape characters in character strings and identifiers. If set sql_mode is set to 'NO_BACKSLASH_ESCAPES', backslashes (\) cannot be parsed as escape characters in character strings and identifiers.

In GaussDB, the standard_conforming_strings parameter is used to determine whether backslashes (\) in character strings and identifiers are parsed as common characters or escape characters. The default value is on, indicating that backslashes (\) are parsed as common text in common character string texts according to the SQL standard. If set standard_conforming_strings is set to off, backslashes (\) can be parsed as escape characters in character strings and identifiers.

14

If the inserted value is less than the number of columns, MySQL reports an error while GaussDB supplements null values.

INSERT

In GaussDB, if the column list is not specified and the inserted value is less than the number of columns, values are assigned based on the column sequence when the table is created by default. If a column has a non-null constraint, an error is reported. If no non-null constraint exists and a default value is specified, the default value is added to the column. If no default value is specified, null is added.

15

The columns sorted in ORDER BY must be included in the columns of the result set.

SELECT

In GaussDB, when used with the GROUP BY clause, the columns to be sorted in ORDER BY must be included in the columns of the result set retrieved by the SELECT statement. When used with the DISTINCT keyword, the columns to be sorted in ORDER BY must be included in the columns of the result set retrieved by the SELECT statement.

16

Do not use ON DUPLICATE KEY UPDATE to modify constraint columns.

INSERT

-

17

Duplicate column names are allowed in the SELECT result.

SELECT

-

18

NATURAL JOIN in GaussDB is different from that in MySQL.

SELECT

In GaussDB, NATURAL [ [LEFT | RIGHT] OUTER] JOIN allows you not to specify LEFT | RIGHT. If LEFT | RIGHT is not specified, NATURAL OUTER JOIN is NATURAL JOIN. You can use JOIN consecutively.

19

If the foreign key data type is timestamp or datetime, an error is reported for attempts to update or delete the foreign table.

UPDATE/DELETE

If the foreign key data type is timestamp or datetime, an error is reported for attempts to update or delete the foreign table, but in MySQL the table can be updated or deleted.

20

Compatibility in terms of nature join and using

SELECT

  • In GaussDB, join sequence is strictly from left to right. MySQL may adjust the sequence.
  • In GaussDB and MySQL, columns involving join in the left or right table cannot be ambiguous during natural join or using. (Generally, ambiguity is caused by duplicate names of columns in the left or right temporary table.) The join sequence differs in two databases, which may lead to different behaviors.
    • Behavior in GaussDB:
      m_regression=# CREATE TABLE t1(a int,b int);
      CREATE TABLE
      m_regression=# CREATE TABLE t2(a int,b int);
      CREATE TABLE
      m_regression=# CREATE TABLE t3(a int,b int);
      CREATE TABLE
      m_regression=# SELECT * FROM t1 JOIN t2;
       a | b | a | b 
      ---+---+---+---
      (0 rows)
      m_regression=# SELECT * FROM t1 JOIN t2 natural join t3; -- Failed. Duplicate contents exist in columns a and b of the temporary table obtained by t1 join t2. Therefore, there is ambiguity in nature join.
      ERROR:  common column name "a" appears more than once in left table
    • Behavior in MySQL:
      mysql> SELECT * FROM t1 JOIN t2 NATURAL JOIN t3;
      Empty set (0.00 sec)
      mysql> SELECT * FROM (t1 join t2) NATURAL JOIN t3;
      ERROR 1052 (23000): Column 'a' in from clause is ambiguous

21

The WITH clause is compatible with MySQL 8.0.

SELECT, INSERT, UPDATE, and DELETE

-

22

Compatibility in terms of join

SELECT

Commas (,) cannot be used as a way of join in GaussDB, but can be used in MySQL.

GaussDB does not support use index for join.

23

If the column expression in the SELECT statement is a function expression or arithmetic expression, the column name in the query result is ?column?.

SELECT

In GaussDB, if the column expression in the SELECT statement is a function expression or arithmetic expression, the column name in the query result is ?column?. In MySQL, the name is the corresponding expression.

24

SELECT export file (into outfile)

SELECT ... INTO OUFILE ...

In the file exported by using the SELECT INTO OUTFILE syntax, the display precision of values of the FLOAT, DOUBLE, and REAL types in GaussDB is different from that in MySQL. The syntax does not affect the import using COPY the values after import.

25

UPDATE/INSERT/REPLACE ... SET specifies the schema name and table name.

UPDATE/INSERT/REPLACE ... SET

The three-segment format for UPDATE/REPLACE SET is database.table.column in MySQL, and is table.column.filed in GaussDB, where filed indicates the attribute in the specified composite type.

For INSERT ... SET, MySQL supports column, table.column, and database.table.column. GaussDB supports only column and does not support table.column and database.table.column.

26

The execution sequence of UPDATE SET is different from that of MySQL.

UPDATE ... SET

In MySQL, UPDATE SET is performed in sequence. The results of UPDATE at the front affect subsequent results of UPDATE, and the same column can be set for multiple times. In GaussDB, all related data is obtained first, and then UPDATE is performed on the data at a time. The same column cannot be set for multiple times.

27

IGNORE feature

INSERT

The execution process in MySQL is different from that in GaussDB. Therefore, the number and information of generated warnings may be different.

28

HAVING syntax

SELECT

In GaussDB, HAVING can only reference columns in the GROUP BY clause or columns used by aggregate functions. However, MySQL supports more: it allows HAVING to reference SELECT columns in the list and columns in external subqueries.