diff --git a/index.js b/index.js index f9f6ec7..c01e22f 100644 --- a/index.js +++ b/index.js @@ -451,6 +451,15 @@ server.get('/addmonth_v', bodyParser.json(), function (req, res) { FROM mmix ) + ,closest AS ( + SELECT + _month + FROM + mmixp + ORDER BY + abs(seq - (select s from mseq where m = '` + req.body.month + `' )) ASC + LIMIT 1 + ) --SELECT * FROM mmixp order by seq asc, vperc desc ,basemix AS ( SELECT @@ -760,7 +769,7 @@ server.get('/addmonth_v', bodyParser.json(), function (req, res) { LEFT OUTER JOIN gld sd ON make_date(mseq.yr + 2020,mseq.cal,m.odom) + rlag + slag BETWEEN sd.sdat AND sd.edat WHERE - m._month = '` + req.body.month + `' + m._month = (SELECT _month FROM closest) ) , ins AS ( INSERT INTO rlarp.osm_fcpool SELECT * FROM final RETURNING * @@ -834,7 +843,7 @@ server.get('/addmonth_v', bodyParser.json(), function (req, res) { ) SELECT json_agg(row_to_json(insagg)) x from insagg ` - //console.log(w); + console.log(w); console.log(req.body); Postgres.FirstRow(w, [], res) //res.json(w) @@ -995,6 +1004,15 @@ server.get('/addmonth_vp', bodyParser.json(), function (req, res) { FROM mmix ) + ,closest AS ( + SELECT + _month + FROM + mmixp + ORDER BY + abs(seq - (select s from mseq where m = '` + req.body.month + `' )) ASC + LIMIT 1 + ) --SELECT * FROM mmixp order by seq asc, vperc desc ,basemix AS ( SELECT @@ -1304,7 +1322,7 @@ server.get('/addmonth_vp', bodyParser.json(), function (req, res) { LEFT OUTER JOIN gld sd ON make_date(mseq.yr + 2020,mseq.cal,m.odom) + rlag + slag BETWEEN sd.sdat AND sd.edat WHERE - m._month = '` + req.body.month + `' + m._month = (SELECT _month FROM closest) ) ,pscale AS ( SELECT @@ -1497,7 +1515,7 @@ server.get('/addmonth_vp', bodyParser.json(), function (req, res) { ,iter ) SELECT json_agg(row_to_json(insagg)) x from insagg` - //console.log(w); + console.log(w); console.log(req.body); Postgres.FirstRow(w, [], res) //res.json(w) diff --git a/route_meta/addmonth_vupd.sql b/route_meta/addmonth_vupd.sql index f0c32d6..0fbcc02 100644 --- a/route_meta/addmonth_vupd.sql +++ b/route_meta/addmonth_vupd.sql @@ -124,6 +124,15 @@ target AS (select -50000 vincr, 20000 pincr) FROM mmix ) +,closest AS ( + SELECT + _month + FROM + mmixp + ORDER BY + abs(seq - (select s from mseq where m = 'Jul' )) ASC + LIMIT 1 +) --SELECT * FROM mmixp order by seq asc, vperc desc ,basemix AS ( SELECT @@ -437,7 +446,7 @@ FROM LEFT OUTER JOIN gld sd ON make_date(mseq.yr + 2020,mseq.cal,m.odom) + rlag + slag BETWEEN sd.sdat AND sd.edat WHERE - m._month = 'Jul' + m._month = (SELECT _month FROM closest) ) ,pscale AS ( SELECT