some example postgresql commands in use
This commit is contained in:
parent
282662d6e1
commit
1ec5023c53
|
@ -0,0 +1,37 @@
|
|||
-- get data for time span from now
|
||||
-- where epoch_time value is used for filtering
|
||||
SELECT
|
||||
epoch_time, aqi_value
|
||||
FROM aqi
|
||||
WHERE epoch_time > 1613975843
|
||||
ORDER BY epoch_time DESC;
|
||||
|
||||
|
||||
-- get data from yesterday
|
||||
SELECT
|
||||
epoch_time, aqi_value
|
||||
FROM aqi
|
||||
WHERE epoch_time > 1613926800
|
||||
AND epoch_time < 1614013200
|
||||
ORDER BY epoch_time DESC
|
||||
LIMIT 30 * 24;
|
||||
|
||||
|
||||
-- last 7 days
|
||||
SELECT
|
||||
epoch_time, aqi_value
|
||||
FROM aqi
|
||||
WHERE epoch_time > 1613494800
|
||||
AND epoch_time < 1614099600
|
||||
ORDER BY epoch_time DESC
|
||||
LIMIT 30 * 24 * 7;
|
||||
|
||||
|
||||
-- last 48h of pm2.5 and pm10 values
|
||||
SELECT
|
||||
epoch_time, pm25, pm10
|
||||
FROM aqi
|
||||
WHERE epoch_time < 1614963600
|
||||
AND epoch_time > 1614790800
|
||||
ORDER BY epoch_time DESC
|
||||
LIMIT 30 * 48;
|
|
@ -0,0 +1,53 @@
|
|||
-- create aqi table
|
||||
CREATE TABLE aqi (
|
||||
epoch_time INT NOT NULL PRIMARY KEY,
|
||||
time_stamp VARCHAR(20) NOT NULL,
|
||||
uptime INT NOT NULL,
|
||||
pm25 FLOAT4 NOT NULL,
|
||||
pm10 FLOAT4 NOT NULL,
|
||||
aqi_value FLOAT4 NOT NULL,
|
||||
aqi_category VARCHAR(40) NOT NULL
|
||||
);
|
||||
|
||||
-- example aqi insert
|
||||
INSERT INTO aqi (
|
||||
epoch_time,
|
||||
time_stamp,
|
||||
uptime,
|
||||
pm25,
|
||||
pm10,
|
||||
aqi_value,
|
||||
aqi_category
|
||||
) VALUES (
|
||||
1613648178, '2021-02-18 18:36:18', 206728, 20.4, 22.8, 67.0, 'Moderate'
|
||||
);
|
||||
|
||||
|
||||
-- create weather table
|
||||
CREATE TABLE weather (
|
||||
epoch_time INT NOT NULL PRIMARY KEY,
|
||||
time_stamp VARCHAR(20) NOT NULL,
|
||||
temperature FLOAT4 NOT NULL,
|
||||
pressure FLOAT4 NOT NULL,
|
||||
humidity FLOAT4 NOT NULL,
|
||||
wind_speed FLOAT4 NOT NULL,
|
||||
wind_direction INT2 NOT NULL,
|
||||
weather_name VARCHAR(29) NOT NULL,
|
||||
weather_icon VARCHAR(3) NOT NULL
|
||||
);
|
||||
|
||||
-- example weather insert
|
||||
INSERT INTO weather (
|
||||
epoch_time,
|
||||
time_stamp,
|
||||
temperature,
|
||||
pressure,
|
||||
humidity,
|
||||
wind_speed,
|
||||
wind_direction,
|
||||
weather_name,
|
||||
weather_icon
|
||||
) VALUES (
|
||||
1613648178, '2021-02-18 18:36:18', 27.32, 982.41,
|
||||
39.62598, 3.09, 40, 'Clouds', '04n'
|
||||
);
|
Loading…
Reference in New Issue