From 02b32c882a5efd6bea1c9841080f1bcf6e1e0813 Mon Sep 17 00:00:00 2001 From: Tiago Amorim Date: Thu, 16 May 2024 16:33:28 +0100 Subject: [PATCH] bug fix: calculating item_ids array size correctly --- migrations/012_shipments.sql | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/migrations/012_shipments.sql b/migrations/012_shipments.sql index 2e3acb2..9511fb3 100644 --- a/migrations/012_shipments.sql +++ b/migrations/012_shipments.sql @@ -39,8 +39,10 @@ DECLARE n_missing_items int; WHERE id = item_id; END LOOP; - SELECT NEW.quantity - COUNT(item_ids) INTO n_missing_items; + + SELECT NEW.quantity - array_length(item_ids, 1) INTO n_missing_items; IF n_missing_items > 0 THEN + RAISE NOTICE 'Missing items: %', n_missing_items; FOR i IN 1..n_missing_items LOOP INSERT INTO items (piece_kind, status, warehouse, acc_cost)