--echo #
--echo # WL#10358 Implement table value constructors: VALUES.
--echo #
--echo # Allowed:
with VALUES for a
--echo # clause.
VALUES ROW(1, 10);
VALUES ROW(1, 10), ROW(2, 20);
--echo # Allowed: Table value constructor inside a subquery.
SELECT * FROM (VALUES ROW(1, 10)) AS dt;
--sorted_result
SELECT * FROM (VALUES ROW(1, 10), ROW(2, 20)) AS dt;
--echo # Allowed: Both old and new syntax for INSERT statements.
CREATE TABLE t0(a INT, b INT);
INSERT INTO t0 VALUES(1, 10);
--sorted_result
INSERT INTO t0 VALUES ROW(2, 20), ROW(3, 30);
SELECT * FROM t0;
DELETE FROM t0;
--echo # Not allowed: Row value expressions of different degree.
--error ER_WRONG_VALUE_COUNT_ON_ROW
VALUES ROW(1, 10), ROW(2);
--error ER_WRONG_VALUE_COUNT_ON_ROW
VALUES ROW(1), ROW(2, 20);
--echo # Allowed: Explicit table clause. Equivalent to SELECT * FROM table_name.
INSERT INTO t0 VALUES(1, 10);
TABLE t0;
SELECT * FROM (TABLE t0) AS dt;
DELETE FROM t0;
--echo # Allowed: Using table value constructors with JOIN.
INSERT INTO t0 VALUES(1, 10);
SELECT * FROM t0 JOIN (VALUES ROW(2, 20)) AS dt;
--sorted_result
SELECT * FROM t0 JOIN (VALUES ROW(2, 20), ROW(3, 30)) AS dt;
--sorted_result
SELECT * FROM t0
LEFT JOIN (VALUES ROW(2, 20), ROW(3, 30)) AS dt
ON t0.a = dt.column_0;
--sorted_result
SELECT * FROM t0
LEFT JOIN (VALUES ROW(1, 20), ROW(1, 30)) AS dt
ON t0.a = dt.column_0;
--sorted_result
SELECT * FROM t0
RIGHT JOIN (VALUES ROW(2, 20), ROW(3, 30)) AS dt
ON t0.a = dt.column_0;
--sorted_result
SELECT * FROM t0
RIGHT JOIN (VALUES ROW(1, 20), ROW(1, 30)) AS dt
ON t0.a = dt.column_0;
--sorted_result
SELECT * FROM (VALUES ROW(1), ROW(2)) AS dt0
NATURAL JOIN (VALUES ROW(1, 10), ROW(2, 20)) AS dt1;
--sorted_result
SELECT * FROM (VALUES ROW(1), ROW(2)) AS dt0
NATURAL JOIN (VALUES ROW(1, 10), ROW(1, 20)) AS dt1;
DELETE FROM t0;
--echo # Allowed: Using table value constructors with UNION.
VALUES ROW(1) UNION SELECT 2;
VALUES ROW(1, 10) UNION SELECT 2, 20;
--echo # Allowed: Scalar subquery as table value constructor value.
VALUES ROW((SELECT 1), 10);
--echo # Allowed: Aggregation of types in table values constructor rows.
VALUES ROW(1, 10), ROW(2, "20");
--echo # Allowed: Creating tables from aggregated types.
CREATE TABLE t AS VALUES ROW(1, 1.0, 1.0e0, DATE '2000-01-01', TIME '00:00:00',
"1", POINT(1, 1), JSON_ARRAY('[1, "2"]'));
DESC t;
DROP TABLE t;
CREATE TABLE t AS VALUES ROW(1, 1, 1, 1, 1, 1, 1, 1),
ROW(1, 1.0, 1.0e0, DATE '2000-01-01', TIME '00:00:00',
"1", POINT(1, 1), JSON_ARRAY('[1, "2"]'));
DESC t;
DROP TABLE t;
--echo # Allowed: Aggregation of types in table value constructor used in UNION.
--sorted_result
SELECT * FROM (VALUES ROW(1, 10), ROW(2, "20") UNION SELECT 3, 30) AS dt;
--echo # Note: Here the columns are named from the first SELECT instead.
--sorted_result
SELECT * FROM (SELECT 1, 10 UNION VALUES ROW(2, 20), ROW(3, "30")) AS dt;
--echo # Allowed: Reference an inner table in subqueries within rows.
INSERT INTO t0 VALUES(1, 10);
VALUES ROW((SELECT a FROM t0), 10);
DELETE FROM t0;
--echo # Allowed: Use table value constructor for subquery predicates.
INSERT INTO t0 VALUES(1, 10), (2, 20);
--sorted_result
SELECT * FROM t0 WHERE a IN (VALUES ROW(1));
--sorted_result
SELECT * FROM t0 WHERE a IN (VALUES ROW(1), ROW(2));
--sorted_result
SELECT * FROM t0 WHERE (a, b) IN (VALUES ROW(1, 10));
--sorted_result
SELECT * FROM t0 WHERE (a, b) IN (VALUES ROW(1, 10), ROW(2, 20));
--sorted_result
SELECT * FROM t0 WHERE a NOT IN (VALUES ROW(1));
--sorted_result
SELECT * FROM t0 WHERE a NOT IN (VALUES ROW(1), ROW(2));
--sorted_result
SELECT * FROM t0 WHERE (a, b) NOT IN (VALUES ROW(1, 10));
--sorted_result
SELECT * FROM t0 WHERE (a, b) NOT IN (VALUES ROW(1, 10), ROW(2, 20));
--sorted_result
SELECT * FROM t0 WHERE a >ALL (VALUES ROW(1));
--sorted_result
SELECT * FROM t0 WHERE a >ALL (VALUES ROW(1), ROW(2));
--sorted_result
SELECT * FROM t0 WHERE a (ARG)' FAILED.
--echo #
CREATE TABLE t1(a INT);
CREATE VIEW v1 AS SELECT a FROM t1;
INSERT INTO v1 VALUES() AS c(a);
INSERT INTO v1 VALUES(5) AS c(a);
SELECT * FROM v1;
DROP VIEW v1;
DROP TABLE t1;