datafuselabs / databend

𝗗𝗮𝘁𝗮, 𝗔𝗻𝗮𝗹𝘆𝘁𝗶𝗰𝘀 & 𝗔𝗜. Modern alternative to Snowflake. Cost-effective and simple for massive-scale analytics. https://databend.com
https://docs.databend.com
Other
7.43k stars 714 forks source link

subquery data type in delete statement should be boolean #13986

Closed BohuTANG closed 5 months ago

BohuTANG commented 6 months ago

Summary

Setup

https://github.com/datafuselabs/wizard/blob/main/checksb/sql/updates/bend/setup.sql

Query

-- UPDATE-A2: Mark all 'pending' orders as 'completed' for ETH, where the price is above average.
UPDATE orders
SET status = 'completed'
WHERE asset_type = 'ETH' AND status = 'pending'
AND price > (SELECT AVG(price) FROM orders WHERE asset_type = 'ETH');

Error:

1001=>subquery data type in delete statement should be boolean

This works in snowflake.

BohuTANG commented 6 months ago

cc @SkyFan2002

BohuTANG commented 6 months ago

Another issue:

-- UPDATE-A3: Double the quantity of XRP in transactions for users who have more than 2 transactions.
UPDATE transactions
SET quantity = quantity * 2
WHERE user_id IN (SELECT user_id FROM transactions GROUP BY user_id HAVING COUNT(*) > 2) AND asset_type = 'XRP';

Errors:

1104=>called `Result::unwrap()` on an `Err` value: BadArguments. Code: 1006, Text = Unable to get field named "asset_type". Valid fields: ["user_id", "_row_id"].

<Backtrace disabled by default. Please use RUST_BACKTRACE=1 to enable> 
BohuTANG commented 6 months ago

Delete issue:

-- DELETE-A5: Delete orders with a quantity greater than the average quantity of all orders
DELETE FROM orders
WHERE quantity > (SELECT AVG(quantity) FROM orders);

Error:

1001=>subquery data type in delete statement should be boolean