From 3b3a2f7b39eb212ab0cc44f4dac90237fb6c8077 Mon Sep 17 00:00:00 2001 From: Paul Trowbridge Date: Fri, 27 Nov 2020 02:24:20 -0500 Subject: [PATCH] return count of inserted rows --- generate_sql/gen_baseline.sql | 6 +++++- index.js | 4 ++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/generate_sql/gen_baseline.sql b/generate_sql/gen_baseline.sql index 7eb03aa..fcb5aa1 100644 --- a/generate_sql/gen_baseline.sql +++ b/generate_sql/gen_baseline.sql @@ -152,6 +152,7 @@ SELECT FROM baseline o$$||E'\n'||_perd_joins||$$ ) +,ins AS ( INSERT INTO fc.live SELECT @@ -160,7 +161,10 @@ FROM incr i WHERE i.$$||_order_date||$$ >= 'app_first_forecast_date'::date$$||$$ - OR i.$$||_ship_date||$$ >= 'app_first_forecast_date'::date$$ + OR i.$$||_ship_date||$$ >= 'app_first_forecast_date'::date$$||$$ +RETURNING * +) +SELECT COUNT(*) num_rows FROM ins$$ --any orders in the forecast period, or any sales in the forecast period (from open orders) INTO _baseline; diff --git a/index.js b/index.js index 35f6682..9639fc7 100644 --- a/index.js +++ b/index.js @@ -87,8 +87,8 @@ server.get('/baseline', bodyParser.json(), function(req, res) { //execute the sql and send the result args.push(req.body.app_baseline_from_date); console.log(sql); - res.send(sql); - //Postgres.FirstRow(sql, [], res) + //res.send(sql); + Postgres.FirstRow(sql, [], res) }; })