Commit f31ca2c5 authored by David Schäfer's avatar David Schäfer
Browse files

bring all queries to the same contraints

parent 5efe7836
......@@ -8,7 +8,7 @@ SELECT
, '' AS sensor_name
FROM LOGGER.MV_LEVEL1_DATA d
WHERE
d.sensor_id in (%s)
d.sensor_id in (%s) -- constraints are enforces through sensors.sql
AND d.timestamp >= LOGGER.DMP_DATE.PARSE(:1)
AND d.timestamp <= LOGGER.DMP_DATE.PARSE(:2)
OFFSET :3 ROWS FETCH NEXT :4 ROWS ONLY
......@@ -14,9 +14,9 @@ SELECT
AND %s = :2
AND r.timestamp_measurement >= LOGGER.DMP_DATE.PARSE(:3)
AND r.timestamp_measurement <= LOGGER.DMP_DATE.PARSE(:4)
AND l.deleted = 0
AND s.virtual_sensor = 0 -- we don't want virtual sensors, as they don't accept upload data
AND s.evaluate_sensor = 1 -- exclude the timestamp only sensors
AND l.deleted = 0 -- leave the dead alone
AND s.deleted = 0
AND s.updated = 0
AND s.virtual_sensor = 0
ORDER BY r.timestamp_measurement, s.sensor_id
OFFSET :5 ROWS FETCH NEXT :6 ROWS ONLY
......@@ -14,10 +14,10 @@ WITH tmp AS (
AND %s = :2
AND r.timestamp_measurement >= LOGGER.DMP_DATE.PARSE(:3)
AND r.timestamp_measurement <= LOGGER.DMP_DATE.PARSE(:4)
AND l.deleted = 0
AND s.virtual_sensor = 0 -- we don't want virtual sensors, as they don't accept upload data
AND s.evaluate_sensor = 1 -- exclude the timestamp only sensors
AND l.deleted = 0 -- leave the dead alone
AND s.deleted = 0
AND s.updated = 0
AND s.virtual_sensor = 0
) SELECT
timestamp_measurement,
%s(value_measurement) AS value_measurement,
......
......@@ -10,7 +10,7 @@ SELECT
, d.quality_cause
, d.quality_comment
FROM LOGGER.MV_LEVEL2A_DATA d
WHERE d.sensor_id IN (%s)
WHERE d.sensor_id IN (%s) -- constraints are enforces through sensors.sql
AND d.timestamp >= LOGGER.DMP_DATE.PARSE(:1)
AND d.timestamp <= LOGGER.DMP_DATE.PARSE(:2)
OFFSET :3 ROWS FETCH NEXT :4 ROWS ONLY
......@@ -18,9 +18,9 @@ SELECT
AND %s = :2
AND r.timestamp_measurement >= LOGGER.DMP_DATE.PARSE(:3)
AND r.timestamp_measurement <= LOGGER.DMP_DATE.PARSE(:4)
AND l.deleted = 0
AND s.virtual_sensor = 0 -- we don't want virtual sensors, as they don't accept upload data
AND s.evaluate_sensor = 1 -- exclude the timestamp only sensors
AND l.deleted = 0 -- leave the dead alone
AND s.deleted = 0
AND s.updated = 0
AND s.virtual_sensor = 0
ORDER BY r.timestamp_measurement, s.sensor_id
OFFSET :5 ROWS FETCH NEXT :6 ROWS ONLY
......@@ -19,10 +19,10 @@ WITH selected AS (
AND %s = :2
AND r.timestamp_measurement >= LOGGER.DMP_DATE.PARSE(:3)
AND r.timestamp_measurement <= LOGGER.DMP_DATE.PARSE(:4)
AND l.deleted = 0
AND s.virtual_sensor = 0 -- we don't want virtual sensors, as they don't accept upload data
AND s.evaluate_sensor = 1 -- exclude the timestamp only sensors
AND l.deleted = 0 -- leave the dead alone
AND s.deleted = 0
AND s.updated = 0
AND s.virtual_sensor = 0
) SELECT
timestamp_measurement AS timestamp_measurement,
MAX(logger_id) AS logger_id,
......
......@@ -21,8 +21,10 @@ SELECT
JOIN LOGGER.LOGGER l on l.logger_id = c.logger_id
JOIN DATENMANAGEMENTPORTAL.ORT o on o.ort_id = s.ort_id
WHERE l.datenprojekt_id = :1
AND s.virtual_sensor = 0
AND s.evaluate_sensor = 1 -- exclude the timestamp only sensors
AND s.virtual_sensor = 0 -- we don't want virtual sensors, as they don't accept upload data
AND s.evaluate_sensor = 1 -- exclude the timestamp only sensors
AND l.deleted = 0 -- leave the dead alone
AND s.deleted = 0
AND c.deleted = 0
%s
ORDER BY s.sensor_id
......
......@@ -9,9 +9,10 @@ SELECT
JOIN logger.logger l on l.logger_id = c.logger_id
WHERE l.datenprojekt_id = :1
AND l.logger_id = :2
AND l.deleted = 0
AND s.virtual_sensor = 0 -- we don't want virtual sensors, as they don't accept upload data
AND s.evaluate_sensor = 1 -- exclude the timestamp only sensors
AND l.deleted = 0 -- leave the dead alone
AND s.deleted = 0
AND s.updated = 0
AND s.virtual_sensor = 0
AND c.deleted = 0
AND c.config_end is NULL
......@@ -13,6 +13,8 @@ SELECT
AND l.logger_id = :2
AND timestamp_measurement >= LOGGER.DMP_DATE.PARSE(:3)
AND timestamp_measurement <= LOGGER.DMP_DATE.PARSE(:4)
AND s.virtual_sensor = 0
AND s.evaluate_sensor = 1
AND s.virtual_sensor = 0 -- we don't want virtual sensors, as they don't accept upload data
AND s.evaluate_sensor = 1 -- exclude the timestamp only sensors
AND l.deleted = 0 -- leave the dead alone
AND s.deleted = 0
ORDER BY s.sensor_id, r.timestamp_measurement
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment