File: create_if_not_exists.result

package info (click to toggle)
mysql-8.0 8.0.43-3
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 1,273,924 kB
  • sloc: cpp: 4,684,605; ansic: 412,450; pascal: 108,398; java: 83,641; perl: 30,221; cs: 27,067; sql: 26,594; sh: 24,181; python: 21,816; yacc: 17,169; php: 11,522; xml: 7,388; javascript: 7,076; makefile: 2,194; lex: 1,075; awk: 670; asm: 520; objc: 183; ruby: 97; lisp: 86
file content (82 lines) | stat: -rw-r--r-- 3,859 bytes parent folder | download
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#
# WL#14722 Support IF NOT EXISTS clause
# in CREATE PROCEDURE/FUNCTION/TRIGGER
#

# 1. Stored Procedures (SPs)

# 1.1. Must execute successfully since the SP does not exist
CREATE PROCEDURE IF NOT EXISTS sp1() BEGIN END;
# 1.2. Must report a warning that the SP already exists
CREATE PROCEDURE IF NOT EXISTS sp1() BEGIN END;
Warnings:
Note	1304	PROCEDURE sp1 already exists
# 1.3. Must fail with error that the SP already exists
CREATE PROCEDURE sp1() BEGIN END;
ERROR 42000: PROCEDURE sp1 already exists
DROP PROCEDURE sp1;

# 2. Stored Functions (SFs)

# 2.1. Must execute successfully since the SF does not exist
CREATE FUNCTION IF NOT EXISTS sf1() RETURNS INT DETERMINISTIC return 0;
# 2.2. Must report a warning since the SF already exists
CREATE FUNCTION IF NOT EXISTS sf1() RETURNS INT DETERMINISTIC return 0;
Warnings:
Note	1304	FUNCTION sf1 already exists
# 2.3. Must fail with error since the SF already exists
CREATE FUNCTION sf1() RETURNS INT DETERMINISTIC return 0;
ERROR 42000: FUNCTION sf1 already exists
DROP FUNCTION sf1;
# 2.4. Must report a warning since it has the same name as a native function
CREATE FUNCTION IF NOT EXISTS abs() RETURNS INT DETERMINISTIC return 0;
Warnings:
Note	1585	This function 'abs' has the same name as a native function
DROP FUNCTION abs;
# 2.5. Must report a warning that UDF will override the SF
CREATE FUNCTION metaphon RETURNS STRING SONAME "UDF_EXAMPLE_LIB";
CREATE FUNCTION IF NOT EXISTS metaphon() RETURNS INT DETERMINISTIC return 0;
Warnings:
Note	4084	This function 'metaphon' has the same name as a loadable function (UDF). To invoke the stored function, it is necessary to qualify it with the schema name.
DROP FUNCTION metaphon;
DROP FUNCTION test.metaphon;

# 3. Loadable Functions / User Defined Functions (UDFs)

# 3.1. Must execute successfully since the UDF does not exist
CREATE FUNCTION IF NOT EXISTS metaphon RETURNS STRING SONAME "UDF_EXAMPLE_LIB";
# 3.2. Must report a warning since the UDF already exists
CREATE FUNCTION IF NOT EXISTS metaphon RETURNS STRING SONAME "UDF_EXAMPLE_LIB";
Warnings:
Note	1125	Function 'metaphon' already exists
# 3.3. Must fail with error since the UDF already exists
CREATE FUNCTION metaphon RETURNS STRING SONAME "UDF_EXAMPLE_LIB";
ERROR HY000: Function 'metaphon' already exists
DROP FUNCTION metaphon;
# 3.4. Must fail with an error since native function already exists
CREATE FUNCTION IF NOT EXISTS sum RETURNS INT SONAME "UDF_EXAMPLE_LIB";
ERROR HY000: This function 'sum' has the same name as a native function. The 'IF NOT EXISTS' clause is not supported while creating a loadable function with the same name as a native function.
# 3.5. Will succeed without warning, but UDF will override the SF
CREATE FUNCTION IF NOT EXISTS metaphon() RETURNS INT DETERMINISTIC return 0;
CREATE FUNCTION metaphon RETURNS STRING SONAME "UDF_EXAMPLE_LIB";
DROP FUNCTION metaphon;
DROP FUNCTION test.metaphon;

# 4. Triggers

CREATE TABLE t1 (a INT);
# 4.1. Must execute successfully since the trigger does not exist
CREATE TRIGGER IF NOT EXISTS trg1 BEFORE INSERT ON t1 FOR EACH ROW BEGIN END;
# 4.2. Must report a warning since the trigger already exists on the same table
CREATE TRIGGER IF NOT EXISTS trg1 BEFORE INSERT ON t1 FOR EACH ROW BEGIN END;
Warnings:
Note	4099	Trigger 'trg1' already exists on the table 'test'.'t1'.
# 4.3. Must fail with error since the trigger already exists on a different table
CREATE TABLE t2 (a INT);
CREATE TRIGGER IF NOT EXISTS trg1 BEFORE INSERT ON t2 FOR EACH ROW BEGIN END;
ERROR HY000: Trigger 'test'.'trg1' already exists on a different table. The 'IF NOT EXISTS' clause is only supported for triggers associated with the same table.
DROP TABLE t2;
# 4.4. Must fail with error since the trigger already exists
CREATE TRIGGER trg1 BEFORE INSERT ON t1 FOR EACH ROW BEGIN END;
ERROR HY000: Trigger already exists
DROP TABLE t1;