Global AND and OR functions for better indentation of a complex condition in the Go code and in the generated SQL.
This commit is contained in:
parent
8ffbe38993
commit
9f91fd705a
17 changed files with 338 additions and 44 deletions
|
|
@ -73,9 +73,9 @@ WITH regional_sales AS (
|
|||
SELECT regional_sales."orders.ship_region" AS "orders.ship_region"
|
||||
FROM regional_sales
|
||||
WHERE regional_sales.total_sales > ((
|
||||
SELECT SUM(regional_sales.total_sales)
|
||||
FROM regional_sales
|
||||
) / 50)
|
||||
SELECT SUM(regional_sales.total_sales)
|
||||
FROM regional_sales
|
||||
) / 50)
|
||||
)
|
||||
SELECT orders.ship_region AS "orders.ship_region",
|
||||
order_details.product_id AS "order_details.product_id",
|
||||
|
|
@ -84,9 +84,9 @@ SELECT orders.ship_region AS "orders.ship_region",
|
|||
FROM northwind.orders
|
||||
INNER JOIN northwind.order_details ON (orders.order_id = order_details.order_id)
|
||||
WHERE orders.ship_region IN (
|
||||
SELECT top_region."orders.ship_region" AS "orders.ship_region"
|
||||
FROM top_region
|
||||
)
|
||||
SELECT top_region."orders.ship_region" AS "orders.ship_region"
|
||||
FROM top_region
|
||||
)
|
||||
GROUP BY orders.ship_region, order_details.product_id
|
||||
ORDER BY SUM(order_details.quantity) DESC;
|
||||
`)
|
||||
|
|
@ -150,18 +150,18 @@ func TestWithStatementDeleteAndInsert(t *testing.T) {
|
|||
WITH remove_discontinued_orders AS (
|
||||
DELETE FROM northwind.order_details
|
||||
WHERE order_details.product_id IN (
|
||||
SELECT products.product_id AS "products.product_id"
|
||||
FROM northwind.products
|
||||
WHERE products.discontinued = $1
|
||||
)
|
||||
SELECT products.product_id AS "products.product_id"
|
||||
FROM northwind.products
|
||||
WHERE products.discontinued = $1
|
||||
)
|
||||
RETURNING order_details.product_id AS "order_details.product_id"
|
||||
),update_discontinued_price AS (
|
||||
UPDATE northwind.products
|
||||
SET unit_price = $2
|
||||
WHERE products.product_id IN (
|
||||
SELECT remove_discontinued_orders."order_details.product_id" AS "order_details.product_id"
|
||||
FROM remove_discontinued_orders
|
||||
)
|
||||
SELECT remove_discontinued_orders."order_details.product_id" AS "order_details.product_id"
|
||||
FROM remove_discontinued_orders
|
||||
)
|
||||
RETURNING products.product_id AS "products.product_id",
|
||||
products.product_name AS "products.product_name",
|
||||
products.supplier_id AS "products.supplier_id",
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue