-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
30aed55
commit d1090ea
Showing
12 changed files
with
208 additions
and
0 deletions.
There are no files selected for viewing
16 changes: 16 additions & 0 deletions
16
testdata/postgresql/complex/delete-complex-subqueries-joins.expected
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
[ | ||
{ | ||
"expected": "DELETE FROM users u USING orders o, order_items oi, products p WHERE u.id = o.user_id AND o.id = oi.order_id AND oi.product_id = p.id AND p.category = ? AND o.order_date < NOW ( ) - INTERVAL ?", | ||
"statement_metadata": { | ||
"size": 11, | ||
"tables": [ | ||
"users" | ||
], | ||
"commands": [ | ||
"DELETE" | ||
], | ||
"comments": [], | ||
"procedures": [] | ||
} | ||
} | ||
] |
12 changes: 12 additions & 0 deletions
12
testdata/postgresql/complex/delete-complex-subqueries-joins.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
DELETE FROM | ||
users u | ||
USING | ||
orders o, | ||
order_items oi, | ||
products p | ||
WHERE | ||
u.id = o.user_id | ||
AND o.id = oi.order_id | ||
AND oi.product_id = p.id | ||
AND p.category = 'obsolete' | ||
AND o.order_date < NOW() - INTERVAL '5 years'; |
21 changes: 21 additions & 0 deletions
21
testdata/postgresql/complex/insert-complex-select-joins.expected
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
[ | ||
{ | ||
"expected": "INSERT INTO order_summaries ( order_id, product_count, total_amount, average_product_price ) SELECT o.id, COUNT ( p.id ), SUM ( oi.amount ), AVG ( p.price ) FROM orders o JOIN order_items oi ON o.id = oi.order_id JOIN products p ON oi.product_id = p.id GROUP BY o.id HAVING SUM ( oi.amount ) > ?", | ||
"statement_metadata": { | ||
"size": 56, | ||
"tables": [ | ||
"order_summaries", | ||
"orders", | ||
"order_items", | ||
"products" | ||
], | ||
"commands": [ | ||
"INSERT", | ||
"SELECT", | ||
"JOIN" | ||
], | ||
"comments": [], | ||
"procedures": [] | ||
} | ||
} | ||
] |
14 changes: 14 additions & 0 deletions
14
testdata/postgresql/complex/insert-complex-select-joins.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
INSERT INTO order_summaries (order_id, product_count, total_amount, average_product_price) | ||
SELECT | ||
o.id, | ||
COUNT(p.id), | ||
SUM(oi.amount), | ||
AVG(p.price) | ||
FROM | ||
orders o | ||
JOIN order_items oi ON o.id = oi.order_id | ||
JOIN products p ON oi.product_id = p.id | ||
GROUP BY | ||
o.id | ||
HAVING | ||
SUM(oi.amount) > 1000; |
20 changes: 20 additions & 0 deletions
20
testdata/postgresql/complex/select-complex-aggregates-subqueries.expected
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
[ | ||
{ | ||
"expected": "SELECT u.id, u.name, ( SELECT COUNT ( * ) FROM orders o WHERE o.user_id = u.id ), ( SELECT SUM ( amount ) FROM payments p WHERE p.user_id = u.id ), ( SELECT AVG ( rating ) FROM reviews r WHERE r.user_id = u.id ) FROM users u WHERE EXISTS ( SELECT ? FROM logins l WHERE l.user_id = u.id AND l.time > NOW ( ) - INTERVAL ? ) AND u.status = ? ORDER BY total_payments DESC, average_rating DESC, order_count DESC LIMIT ?", | ||
"statement_metadata": { | ||
"size": 38, | ||
"tables": [ | ||
"orders", | ||
"payments", | ||
"reviews", | ||
"users", | ||
"logins" | ||
], | ||
"commands": [ | ||
"SELECT" | ||
], | ||
"comments": [], | ||
"procedures": [] | ||
} | ||
} | ||
] |
16 changes: 16 additions & 0 deletions
16
testdata/postgresql/complex/select-complex-aggregates-subqueries.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
SELECT | ||
u.id, | ||
u.name, | ||
(SELECT COUNT(*) FROM orders o WHERE o.user_id = u.id) AS order_count, | ||
(SELECT SUM(amount) FROM payments p WHERE p.user_id = u.id) AS total_payments, | ||
(SELECT AVG(rating) FROM reviews r WHERE r.user_id = u.id) AS average_rating | ||
FROM | ||
users u | ||
WHERE | ||
EXISTS ( | ||
SELECT 1 FROM logins l WHERE l.user_id = u.id AND l.time > NOW() - INTERVAL '1 month' | ||
) | ||
AND u.status = 'active' | ||
ORDER BY | ||
total_payments DESC, average_rating DESC, order_count DESC | ||
LIMIT 10; |
18 changes: 18 additions & 0 deletions
18
testdata/postgresql/complex/select-complex-joins-window-functions.expected
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
[ | ||
{ | ||
"expected": "SELECT e?.name, e?.salary, e?.name, AVG ( e?.salary ) OVER ( PARTITION BY e?.manager_id ), RANK ( ) OVER ( ORDER BY e?.salary DESC ) FROM employees e? LEFT JOIN employees e? ON e?.manager_id = e?.id WHERE e?.department_id IN ( SELECT id FROM departments WHERE name LIKE ? ) AND e?.hire_date > ? ORDER BY salary_rank, avg_manager_salary DESC", | ||
"statement_metadata": { | ||
"size": 30, | ||
"tables": [ | ||
"employees", | ||
"departments" | ||
], | ||
"commands": [ | ||
"SELECT", | ||
"JOIN" | ||
], | ||
"comments": [], | ||
"procedures": [] | ||
} | ||
} | ||
] |
15 changes: 15 additions & 0 deletions
15
testdata/postgresql/complex/select-complex-joins-window-functions.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
SELECT | ||
e1.name AS employee_name, | ||
e1.salary, | ||
e2.name AS manager_name, | ||
AVG(e2.salary) OVER (PARTITION BY e1.manager_id) AS avg_manager_salary, | ||
RANK() OVER (ORDER BY e1.salary DESC) AS salary_rank | ||
FROM | ||
employees e1 | ||
LEFT JOIN employees e2 ON e1.manager_id = e2.id | ||
WHERE | ||
e1.department_id IN (SELECT id FROM departments WHERE name LIKE 'IT%') | ||
AND | ||
e1.hire_date > '2020-01-01' | ||
ORDER BY | ||
salary_rank, avg_manager_salary DESC; |
16 changes: 16 additions & 0 deletions
16
testdata/postgresql/complex/select-nested-subqueries-aggregates-limits.expected
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
[ | ||
{ | ||
"expected": "SELECT user_id, order_id, order_total, user_total FROM ( SELECT o.user_id, o.id, o.total, ( SELECT SUM ( total ) FROM orders WHERE user_id = o.user_id ), RANK ( ) OVER ( PARTITION BY o.user_id ORDER BY o.total DESC ) FROM orders o ) sub WHERE sub.rnk = ? AND user_total > ( SELECT AVG ( total ) * ? FROM orders )", | ||
"statement_metadata": { | ||
"size": 12, | ||
"tables": [ | ||
"orders" | ||
], | ||
"commands": [ | ||
"SELECT" | ||
], | ||
"comments": [], | ||
"procedures": [] | ||
} | ||
} | ||
] |
22 changes: 22 additions & 0 deletions
22
testdata/postgresql/complex/select-nested-subqueries-aggregates-limits.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
SELECT | ||
user_id, | ||
order_id, | ||
order_total, | ||
user_total | ||
FROM ( | ||
SELECT | ||
o.user_id, | ||
o.id AS order_id, | ||
o.total AS order_total, | ||
(SELECT SUM(total) FROM orders WHERE user_id = o.user_id) AS user_total, | ||
RANK() OVER (PARTITION BY o.user_id ORDER BY o.total DESC) AS rnk | ||
FROM | ||
orders o | ||
) sub | ||
WHERE | ||
sub.rnk = 1 | ||
AND user_total > ( | ||
SELECT | ||
AVG(total) * 2 | ||
FROM orders | ||
); |
18 changes: 18 additions & 0 deletions
18
testdata/postgresql/complex/update-complex-subquery-conditional.expected
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
[ | ||
{ | ||
"expected": "UPDATE products p SET price = CASE WHEN p.stock < ? THEN p.price * ? WHEN p.stock BETWEEN ? AND ? THEN p.price ELSE p.price * ? END, last_updated = NOW ( ) FROM ( SELECT product_id, SUM ( quantity ) FROM inventory GROUP BY product_id ) WHERE sub.product_id = p.id", | ||
"statement_metadata": { | ||
"size": 29, | ||
"tables": [ | ||
"products", | ||
"inventory" | ||
], | ||
"commands": [ | ||
"UPDATE", | ||
"SELECT" | ||
], | ||
"comments": [], | ||
"procedures": [] | ||
} | ||
} | ||
] |
20 changes: 20 additions & 0 deletions
20
testdata/postgresql/complex/update-complex-subquery-conditional.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
UPDATE | ||
products p | ||
SET | ||
price = CASE | ||
WHEN p.stock < 10 THEN p.price * 1.10 | ||
WHEN p.stock BETWEEN 10 AND 50 THEN p.price | ||
ELSE p.price * 0.90 | ||
END, | ||
last_updated = NOW() | ||
FROM ( | ||
SELECT | ||
product_id, | ||
SUM(quantity) AS stock | ||
FROM | ||
inventory | ||
GROUP BY | ||
product_id | ||
) AS sub | ||
WHERE | ||
sub.product_id = p.id; |