should be it

This commit is contained in:
2025-10-24 19:21:19 -05:00
parent a4b23fc57c
commit f09560c7b1
14047 changed files with 3161551 additions and 1 deletions

View File

@@ -0,0 +1,48 @@
# name: test/sql/merge/merge_into_constraint.test
# description: Test MERGE INTO with constraints
# group: [merge]
statement ok
PRAGMA enable_verification
statement ok
CREATE TABLE Stock(item_id int NOT NULL, balance int, CHECK (balance>0));
statement error
MERGE INTO Stock USING (VALUES (NULL, NULL)) new_accounts(item_id, balance) USING (item_id)
WHEN NOT MATCHED THEN INSERT VALUES (new_accounts.item_id, new_accounts.balance)
----
NOT NULL constraint
statement ok
MERGE INTO Stock USING (VALUES (1, 10)) new_accounts(item_id, balance) USING (item_id)
WHEN NOT MATCHED THEN INSERT VALUES (new_accounts.item_id, new_accounts.balance)
# trying to delete too much
statement error
MERGE INTO Stock USING (VALUES (1, 15)) sales(item_id, volume) USING (item_id)
WHEN MATCHED THEN UPDATE SET balance = balance - volume
----
CHECK constraint
# binding with check constraints
statement ok
CREATE TABLE Items(item_id int NOT NULL, total_cost INTEGER, base_cost INTEGER, tax_cost INTEGER, CHECK (total_cost = base_cost + tax_cost));
statement ok
INSERT INTO Items VALUES (1, 10, 8, 2);
statement error
MERGE INTO Items USING (VALUES (1, 15)) new_prices(item_id, total_cost) USING (item_id)
WHEN MATCHED THEN UPDATE SET total_cost = new_prices.total_cost
----
CHECK constraint
statement ok
MERGE INTO Items USING (VALUES (1, 15)) new_prices(item_id, total_cost) USING (item_id)
WHEN MATCHED THEN UPDATE SET total_cost = new_prices.total_cost, base_cost = new_prices.total_cost - 2
query IIII
FROM Items
----
1 15 13 2