summaryrefslogtreecommitdiffstats
path: root/tests/fixtures
diff options
context:
space:
mode:
Diffstat (limited to 'tests/fixtures')
-rw-r--r--tests/fixtures/identity.sql1
-rw-r--r--tests/fixtures/optimizer/merge_subqueries.sql15
-rw-r--r--tests/fixtures/optimizer/optimizer.sql36
3 files changed, 52 insertions, 0 deletions
diff --git a/tests/fixtures/identity.sql b/tests/fixtures/identity.sql
index 0953fee..f999620 100644
--- a/tests/fixtures/identity.sql
+++ b/tests/fixtures/identity.sql
@@ -717,6 +717,7 @@ UPDATE tbl_name SET foo = 123, bar = 345
UPDATE db.tbl_name SET foo = 123 WHERE tbl_name.bar = 234
UPDATE db.tbl_name SET foo = 123, foo_1 = 234 WHERE tbl_name.bar = 234
UPDATE products SET price = price * 1.10 WHERE price <= 99.99 RETURNING name, price AS new_price
+UPDATE t1 AS a, t2 AS b, t3 AS c LEFT JOIN t4 AS d ON c.id = d.id SET a.id = 1
TRUNCATE TABLE x
OPTIMIZE TABLE y
VACUUM FREEZE my_table
diff --git a/tests/fixtures/optimizer/merge_subqueries.sql b/tests/fixtures/optimizer/merge_subqueries.sql
index b89e2fb..eec8a73 100644
--- a/tests/fixtures/optimizer/merge_subqueries.sql
+++ b/tests/fixtures/optimizer/merge_subqueries.sql
@@ -310,6 +310,21 @@ FROM
t1;
SELECT x.a AS a, x.b AS b, ROW_NUMBER() OVER (PARTITION BY x.a ORDER BY x.a) AS row_num FROM x AS x;
+# title: Don't merge window functions, inner table is aliased in outer query
+with t1 as (
+ SELECT
+ ROW_NUMBER() OVER (PARTITION BY x.a ORDER BY x.a) as row_num
+ FROM
+ x
+)
+SELECT
+ t2.row_num
+FROM
+ t1 AS t2
+WHERE
+ t2.row_num = 2;
+WITH t1 AS (SELECT ROW_NUMBER() OVER (PARTITION BY x.a ORDER BY x.a) AS row_num FROM x AS x) SELECT t2.row_num AS row_num FROM t1 AS t2 WHERE t2.row_num = 2;
+
# title: Values Test
# dialect: spark
WITH t1 AS (
diff --git a/tests/fixtures/optimizer/optimizer.sql b/tests/fixtures/optimizer/optimizer.sql
index 18ee804..4a994c1 100644
--- a/tests/fixtures/optimizer/optimizer.sql
+++ b/tests/fixtures/optimizer/optimizer.sql
@@ -987,3 +987,39 @@ SELECT
FROM "SALES" AS "SALES"
WHERE
"SALES"."INSERT_TS" > '2023-08-07 21:03:35.590 -0700';
+
+# title: using join without select *
+# execute: false
+with
+ alias1 as (select * from table1),
+ alias2 as (select * from table2),
+ alias3 as (
+ select
+ cid,
+ min(od) as m_od,
+ count(odi) as c_od,
+ from alias2
+ group by 1
+ )
+select
+ alias1.cid,
+ alias3.m_od,
+ coalesce(alias3.c_od, 0) as c_od,
+from alias1
+left join alias3 using (cid);
+WITH "alias3" AS (
+ SELECT
+ "table2"."cid" AS "cid",
+ MIN("table2"."od") AS "m_od",
+ COUNT("table2"."odi") AS "c_od"
+ FROM "table2" AS "table2"
+ GROUP BY
+ "table2"."cid"
+)
+SELECT
+ "table1"."cid" AS "cid",
+ "alias3"."m_od" AS "m_od",
+ COALESCE("alias3"."c_od", 0) AS "c_od"
+FROM "table1" AS "table1"
+LEFT JOIN "alias3"
+ ON "table1"."cid" = "alias3"."cid";