Commit cf93209c authored by Monty's avatar Monty Committed by Sergei Golubchik

MDEV-20021 sql_mode="oracle" does not support MINUS set operator

MINUS is mapped to EXCEPT
One consequence of the patch is that MINUS becomes a reserved word in
Oracle mode.

Author: woqutech
parent b8c31595
CREATE TABLE tx1 (c1 int, c2 varchar(30));
CREATE TABLE tx2 (c1 int, c2 varchar(30));
CREATE TABLE tx3 (c1 int, c2 varchar(30));
INSERT INTO tx1 VALUES (1, 'jim');
INSERT INTO tx1 VALUES (2, 'menny');
INSERT INTO tx1 VALUES (3, 'linda');
INSERT INTO tx2 VALUES (1, 'jim');
INSERT INTO tx2 VALUES (2, 'kris');
INSERT INTO tx2 VALUES (3, 'shory');
INSERT INTO tx3 VALUES (1, 'jim');
INSERT INTO tx3 VALUES (2, 'kris');
INSERT INTO tx3 VALUES (3, 'linda');
#
# test when sql_mode is not oracle
#
SELECT c2 FROM tx1 EXCEPT SELECT c2 from tx2;
c2
menny
linda
SELECT c2 FROM tx1 MINUS SELECT c2 from tx2;
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'SELECT c2 from tx2' at line 1
create table MINUS (a int);
drop table MINUS;
#
# test when sql_mode is oracle
#
SET sql_mode=ORACLE;
SELECT c2 FROM tx1 MINUS SELECT c2 from tx2;
c2
menny
linda
SELECT c2 FROM tx1 MINUS SELECT c2 from tx2 MINUS SELECT c2 from tx3;
c2
menny
SELECT c2 FROM tx1 MINUS SELECT c2 from tx2 EXCEPT SELECT c2 from tx3;
c2
menny
SELECT c2 FROM tx1 MINUS SELECT c2 from tx2 UNION SELECT c2 from tx3;
c2
jim
menny
linda
kris
create table MINUS (a int);
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'MINUS (a int)' at line 1
DROP TABLE tx1;
DROP TABLE tx2;
DROP TABLE tx3;
CREATE TABLE tx1 (c1 int, c2 varchar(30));
CREATE TABLE tx2 (c1 int, c2 varchar(30));
CREATE TABLE tx3 (c1 int, c2 varchar(30));
INSERT INTO tx1 VALUES (1, 'jim');
INSERT INTO tx1 VALUES (2, 'menny');
INSERT INTO tx1 VALUES (3, 'linda');
INSERT INTO tx2 VALUES (1, 'jim');
INSERT INTO tx2 VALUES (2, 'kris');
INSERT INTO tx2 VALUES (3, 'shory');
INSERT INTO tx3 VALUES (1, 'jim');
INSERT INTO tx3 VALUES (2, 'kris');
INSERT INTO tx3 VALUES (3, 'linda');
--echo #
--echo # test when sql_mode is not oracle
--echo #
SELECT c2 FROM tx1 EXCEPT SELECT c2 from tx2;
--error 1064
SELECT c2 FROM tx1 MINUS SELECT c2 from tx2;
# MINUS should not be a reserved word
create table MINUS (a int);
drop table MINUS;
--echo #
--echo # test when sql_mode is oracle
--echo #
SET sql_mode=ORACLE;
SELECT c2 FROM tx1 MINUS SELECT c2 from tx2;
SELECT c2 FROM tx1 MINUS SELECT c2 from tx2 MINUS SELECT c2 from tx3;
SELECT c2 FROM tx1 MINUS SELECT c2 from tx2 EXCEPT SELECT c2 from tx3;
SELECT c2 FROM tx1 MINUS SELECT c2 from tx2 UNION SELECT c2 from tx3;
# MINUS should be a reserved word
--error ER_PARSE_ERROR
create table MINUS (a int);
DROP TABLE tx1;
DROP TABLE tx2;
DROP TABLE tx3;
\ No newline at end of file
......@@ -8,5 +8,5 @@ SELECT 1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1
####################################
SELECT event_name, digest, digest_text, sql_text FROM events_statements_history_long;
event_name digest digest_text sql_text
statement/sql/select 62764f94ca18cf720c44d84579e05e60 SELECT ? + ? + SELECT ...
statement/sql/truncate 5947880b8ba439f0ed3ff0bfbb04eebf TRUNCATE TABLE truncat...
statement/sql/select bb82f2829bcdfd9ac1e53f7b27829d36 SELECT ? + ? + SELECT ...
statement/sql/truncate fd6a2d48e5fda6a3f990cb8810136546 TRUNCATE TABLE truncat...
......@@ -404,6 +404,7 @@ static SYMBOL symbols[] = {
{ "MICROSECOND", SYM(MICROSECOND_SYM)},
{ "MIDDLEINT", SYM(MEDIUMINT)}, /* For powerbuilder */
{ "MIGRATE", SYM(MIGRATE_SYM)},
{ "MINUS", SYM(MINUS_ORACLE_SYM)},
{ "MINUTE", SYM(MINUTE_SYM)},
{ "MINUTE_MICROSECOND", SYM(MINUTE_MICROSECOND_SYM)},
{ "MINUTE_SECOND", SYM(MINUTE_SECOND_SYM)},
......
......@@ -1404,6 +1404,7 @@ int Lex_input_stream::find_keyword(Lex_ident_cli_st *kwd,
case EXCEPTION_MARIADB_SYM: return EXCEPTION_ORACLE_SYM;
case EXIT_MARIADB_SYM: return EXIT_ORACLE_SYM;
case GOTO_MARIADB_SYM: return GOTO_ORACLE_SYM;
case MINUS_ORACLE_SYM: return EXCEPT_SYM;
case NUMBER_MARIADB_SYM: return NUMBER_ORACLE_SYM;
case OTHERS_MARIADB_SYM: return OTHERS_ORACLE_SYM;
case PACKAGE_MARIADB_SYM: return PACKAGE_ORACLE_SYM;
......
......@@ -592,6 +592,7 @@ End SQL_MODE_ORACLE_SPECIFIC */
%token <kwd> MEDIUMINT
%token <kwd> MEDIUMTEXT
%token <kwd> MIN_SYM /* SQL-2003-N */
%token <kwd> MINUS_ORACLE_SYM /* Oracle-R */
%token <kwd> MINUTE_MICROSECOND_SYM
%token <kwd> MINUTE_SECOND_SYM
%token <kwd> MODIFIES_SYM /* SQL-2003-R */
......@@ -16037,6 +16038,9 @@ keyword_sp_var_and_label:
| MICROSECOND_SYM
| MIGRATE_SYM
| MINUTE_SYM
/* Start SQL_MODE_DEFAULT_SPECIFIC */
| MINUS_ORACLE_SYM
/* End SQL_MODE_DEFAULT_SPECIFIC */
| MINVALUE_SYM
| MIN_ROWS
| MODIFY_SYM
......@@ -16329,6 +16333,9 @@ reserved_keyword_udt_not_param_type:
| MINUTE_MICROSECOND_SYM
| MINUTE_SECOND_SYM
| MIN_SYM
/* Start SQL_MODE_ORACLE_SPECIFIC
| MINUS_ORACLE_SYM
End SQL_MODE_ORACLE_SPECIFIC */
| MODIFIES_SYM
| MOD_SYM
| NATURAL
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment