3 |
Support the REPLACE INTO syntax. |
REPLACE |
|
7 |
Compatible with INSERT IGNORE. |
INSERT IGNORE |
- GaussDB displays the error information after the downgrade. MySQL records the error information after the downgrade to the error stack and runs the show warnings; command to view the error information. For example:
- Time type difference. For example:
- The default values of date, datetime, and timestamp in GaussDB are 0.
gaussdb=# CREATE TABLE test(f1 DATE NOT NULL, f2 DATETIME NOT NULL, f3 TIMESTAMP NOT NULL);
CREATE TABLE
gaussdb=# INSERT IGNORE INTO test VALUES(NULL, NULL, NULL);
WARNING: null value in column "f1" violates not-null constraint
DETAIL: Failing row contains (null, null, null, null).
WARNING: null value in column "f2" violates not-null constraint
DETAIL: Failing row contains (null, null, null, null).
WARNING: null value in column "f3" violates not-null constraint
DETAIL: Failing row contains (null, null, null, null).
INSERT 0 1
gaussdb=#
SELECT * FROM test;
f1 | f2 | f3
------------+---------------------+---------------------
1970-01-01 | 1970-01-01 00:00:00 | 1970-01-01 00:00:00
(1 row)
- The default values of date, datetime, and timestamp in MySQL are 0.
mysql> CREATE TABLE test(f1 DATE NOT NULL, f2 DATETIME NOT NULL, f3 TIMESTAMP NOT NULL);
Query OK, 0 rows affected (0.00 sec)
mysql> INSERT IGNORE INTO test VALUES(NULL, NULL, NULL);
Query OK, 1 row affected, 3 warnings (0.00 sec)
mysql> show warnings;
+---------+------+----------------------------+
| Level | Code | Message |
+---------+------+----------------------------+
| Warning | 1048 | Column 'f1' cannot be null |
| Warning | 1048 | Column 'f2' cannot be null |
| Warning | 1048 | Column 'f3' cannot be null |
+---------+------+----------------------------+
3 rows in set (0.00 sec)
mysql> SELECT * FROM test;
+------------+---------------------+---------------------+
| f1 | f2 | f3 |
+------------+---------------------+---------------------+
| 0000-00-00 | 0000-00-00 00:00:00 | 0000-00-00 00:00:00 |
+------------+---------------------+---------------------+
1 row in set (0.00 sec)
- GaussDB does not support the MySQL bit type. Therefore, the INSERT IGNORE error downgrade is not supported when the NOT NULL constraint of the bit type is ignored and the length of the inserted bit type is different from that defined.
- Bit type in GaussDB
gaussdb=# CREATE TABLE test(f1 BIT(10) NOT NULL);
CREATE TABLE
gaussdb=# INSERT IGNORE INTO test VALUES(NULL);
ERROR: Un-support feature
DETAIL: ignore null for insert statement is not supported in column f1.
gaussdb=# INSERT IGNORE INTO test VALUES('1010');
ERROR: bit string length 4 does not match type bit(10)
CONTEXT: referenced column: f1
-
Bit type in MySQL
mysql> CREATE TABLE test(f1 BIT(10) NOT NULL);
Query OK, 0 rows affected (0.00 sec)
mysql> INSERT IGNORE INTO test VALUES(NULL);
Query OK, 1 row affected, 1 warning (0.00 sec)
mysql> INSERT IGNORE INTO test VALUES('1010');
Query OK, 1 row affected, 1 warning (0.01 sec)
-
If the precision is specified for the time type in MySQL, the precision is displayed when the zero value is inserted. It is not displayed in GaussDB. For example:
- Time precision specified in GaussDB
gaussdb=# CREATE TABLE test(f1 TIME(3) NOT NULL, f2 DATETIME(3) NOT NULL, f3 TIMESTAMP(3) NOT NULL);
CREATE TABLE
gaussdb=# INSERT IGNORE INTO test VALUES(NULL,NULL,NULL);
WARNING: null value in column "f1" violates not-null constraint
DETAIL: Failing row contains (null, null, null).
WARNING: null value in column "f2" violates not-null constraint
DETAIL: Failing row contains (null, null, null).
WARNING: null value in column "f3" violates not-null constraint
DETAIL: Failing row contains (null, null, null).
INSERT 0 1
gaussdb=# SELECT * FROM test;
f1 | f2 | f3
----------+---------------------+---------------------
00:00:00 | 1970-01-01 00:00:00 | 1970-01-01 00:00:00
(1 row)
-
Time precision specified in MySQL
mysql> CREATE TABLE test(f1 TIME(3) NOT NULL, f2 DATETIME(3) NOT NULL, f3 TIMESTAMP(3) NOT NULL);
Query OK, 0 rows affected (0.00 sec)
mysql> INSERT IGNORE INTO test VALUES(NULL,NULL,NULL);
Query OK, 1 row affected, 3 warnings (0.00 sec)
mysql> SELECT * FROM test;
+--------------+-------------------------+-------------------------+
| f1 | f2 | f3 |
+--------------+-------------------------+-------------------------+
| 00:00:00.000 | 0000-00-00 00:00:00.000 | 0000-00-00 00:00:00.000 |
+--------------+-------------------------+-------------------------+
1 row in set (0.00 sec)
- The execution process in MySQL is different from that in GaussDB. Therefore, the number of generated warnings may be different. For example:
- Number of warnings generated in GaussDB
gaussdb=# CREATE TABLE test(f1 INT, f2 INT not null);
CREATE TABLE
gaussdb=# INSERT INTO test VALUES(1,0),(3,0),(5,0);
INSERT 0 3
gaussdb=# INSERT IGNORE INTO test SELECT f1+1, f1/f2 FROM test;
WARNING: division by zero
CONTEXT: referenced column: f2
WARNING: null value in column "f2" violates not-null constraint
DETAIL: Failing row contains (2, null).
WARNING: division by zero
CONTEXT: referenced column: f2
WARNING: null value in column "f2" violates not-null constraint
DETAIL: Failing row contains (4, null).
WARNING: division by zero
CONTEXT: referenced column: f2
WARNING: null value in column "f2" violates not-null constraint
DETAIL: Failing row contains (6, null).
INSERT 0 3
- Number of warnings generated in MySQL
mysql> CREATE TABLE test(f1 INT, f2 INT not null);
Query OK, 0 rows affected (0.01 sec)
mysql> INSERT INTO test VALUES(1,0),(3,0),(5,0);
Query OK, 3 rows affected (0.00 sec)
Records: 3 Duplicates: 0 Warnings: 0
mysql> INSERT IGNORE INTO test SELECT f1+1, f1/f2 FROM test;
Query OK, 3 rows affected, 4 warnings (0.00 sec)
Records: 3 Duplicates: 0 Warnings: 4
-
The differences between MySQL's and GaussDB's INSERT IGNORE in triggers are as follows:
- INSERT IGNORE used in a GaussDB trigger
gaussdb=# CREATE TABLE test1(f1 INT NOT NULL);
CREATE TABLE
gaussdb=# CREATE TABLE test2(f1 INT);
CREATE TABLE
gaussdb=# CREATE OR REPLACE FUNCTION trig_test() RETURNS TRIGGER AS $$
gaussdb$# BEGIN
gaussdb$# INSERT IGNORE INTO test1 VALUES(NULL);
gaussdb$# RETURN NEW;
gaussdb$# END;
gaussdb$# $$ LANGUAGE plpgsql;
CREATE FUNCTION
gaussdb=# CREATE TRIGGER trig2 BEFORE INSERT ON test2 FOR EACH ROW EXECUTE PROCEDURE trig_test();
CREATE TRIGGER
gaussdb=# INSERT INTO test2 VALUES(NULL);
WARNING: null value in column "f1" violates not-null constraint
DETAIL: Failing row contains (null).
CONTEXT: SQL statement "INSERT IGNORE INTO test1 VALUES(NULL)"
PL/pgSQL function trig_test() line 3 at SQL statement
INSERT 0 1
gaussdb=# SELECT * FROM test1;
f1
----
0
(1 rows)
gaussdb=# SELECT * FROM test2;
f1
----
(1 rows)
-
INSERT IGNORE used in a MySQL trigger
mysql> CREATE TABLE test1(f1 INT NOT NULL);
Query OK, 0 rows affected (0.01 sec)
mysql> CREATE TABLE test2(f1 INT);
Query OK, 0 rows affected (0.00 sec)
mysql> DELIMITER ||
mysql> CREATE TRIGGER trig2 BEFORE INSERT ON test2 FOR EACH ROW
-> BEGIN
-> INSERT IGNORE into test1 values(NULL);
-> END||
Query OK, 0 rows affected (0.01 sec)
mysql> DELIMITER ;
mysql> INSERT INTO test2 VALUES(NULL);
ERROR 1048 (23000): Column 'f1' cannot be null
mysql> INSERT IGNORE INTO test2 VALUES(NULL);
Query OK, 1 row affected (0.00 sec)
mysql> SELECT * FROM test1;
+----+
| f1 |
+----+
| 0 |
+----+
1 row in set (0.00 sec)
mysql> SELECT * FROM test2;
+------+
| f1 |
+------+
| NULL |
+------+
1 row in set (0.00 sec)
-
The implementation mechanism of Boolean and serial in GaussDB is different from that in MySQL. Therefore, the default zero value in GaussDB is different from that in MySQL. For example:
- Behavior in GaussDB
gaussdb=# CREATE TABLE test(f1 SERIAL, f2 BOOL NOT NULL);
NOTICE: CREATE TABLE will create implicit sequence "test_f1_seq" for serial column "test.f1"
CREATE TABLE
gaussdb=# INSERT IGNORE INTO test values(NULL,NULL);
WARNING: null value in column "f1" violates not-null constraint
DETAIL: Failing row contains (null, null).
WARNING: null value in column "f2" violates not-null constraint
DETAIL: Failing row contains (null, null).
INSERT 0 1
gaussdb=# SELECT * FROM test;
f1 | f2
----+----
0 | f
(1 row)
-
Behavior in MySQL
mysql> CREATE TABLE test(f1 SERIAL, f2 BOOL NOT NULL);
Query OK, 0 rows affected (0.00 sec)
mysql> INSERT IGNORE INTO test values(NULL,NULL);
Query OK, 1 row affected, 1 warning (0.00 sec)
mysql> SELECT * FROM test;
+----+----+
| f1 | f2 |
+----+----+
| 1 | 0 |
+----+----+
1 row in set (0.00 sec)
|