|
| 1 | +CREATE TABLE weather ( |
| 2 | + id SERIAL PRIMARY KEY, |
| 3 | + date DATE NOT NULL UNIQUE, |
| 4 | + min_temp FLOAT, |
| 5 | + max_temp FLOAT, |
| 6 | + rainfall FLOAT, |
| 7 | + humidity_9am INTEGER, |
| 8 | + humidity_3pm INTEGER, |
| 9 | + temp_9am FLOAT, |
| 10 | + temp_3pm FLOAT, |
| 11 | + current_temp FLOAT, |
| 12 | + current_humidity INTEGER, |
| 13 | + current_weather_description VARCHAR, |
| 14 | + created_by VARCHAR(50) NOT NULL DEFAULT current_user, |
| 15 | + created_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT current_timestamp, |
| 16 | + updated_by VARCHAR(50), |
| 17 | + updated_at TIMESTAMP WITH TIME ZONE, |
| 18 | + CONSTRAINT weather_date_check CHECK (date <= CURRENT_DATE), |
| 19 | + CONSTRAINT weather_min_max_temp_check CHECK (min_temp <= max_temp), |
| 20 | + CONSTRAINT weather_temp_9am_range_check CHECK (temp_9am BETWEEN -273.15 AND 100.0), |
| 21 | + CONSTRAINT weather_temp_3pm_range_check CHECK (temp_3pm BETWEEN -273.15 AND 100.0), |
| 22 | + CONSTRAINT weather_current_temp_range_check CHECK (current_temp BETWEEN -273.15 AND 100.0), |
| 23 | + CONSTRAINT weather_min_temp_range_check CHECK (min_temp BETWEEN -273.15 AND 100.0), |
| 24 | + CONSTRAINT weather_max_temp_range_check CHECK (max_temp BETWEEN -273.15 AND 100.0), |
| 25 | + CONSTRAINT weather_max_rainfall_check CHECK (rainfall <= 1000.0), |
| 26 | + CONSTRAINT weather_created_by_check CHECK (created_at <= CURRENT_TIMESTAMP), |
| 27 | + CONSTRAINT weather_updated_by_check CHECK (updated_at IS NULL OR updated_at <= CURRENT_TIMESTAMP) |
| 28 | +); |
| 29 | + |
| 30 | +COMMENT ON TABLE weather IS 'Table storing weather data including historical and current weather details'; |
| 31 | +COMMENT ON COLUMN weather.id IS 'ID of the table'; |
| 32 | +COMMENT ON COLUMN weather.date IS 'Date for the record about the weather'; |
| 33 | +COMMENT ON COLUMN weather.min_temp IS 'Minimum temperature of the day'; |
| 34 | +COMMENT ON COLUMN weather.max_temp IS 'Maximum temperature of the day'; |
| 35 | +COMMENT ON COLUMN weather.rainfall IS 'Rainfall in millimeters'; |
| 36 | +COMMENT ON COLUMN weather.humidity_9am IS 'Humidity percentage at 9 AM'; |
| 37 | +COMMENT ON COLUMN weather.humidity_3pm IS 'Humidity percentage at 3 PM'; |
| 38 | +COMMENT ON COLUMN weather.temp_9am IS 'Temperature at 9 AM'; |
| 39 | +COMMENT ON COLUMN weather.temp_3pm IS 'Temperature at 3 PM'; |
| 40 | +COMMENT ON COLUMN weather.current_temp IS 'Current temperature from the API'; |
| 41 | +COMMENT ON COLUMN weather.current_humidity IS 'Current humidity percentage from the API'; |
| 42 | +COMMENT ON COLUMN weather.current_weather_description IS 'Current weather description from the API'; |
| 43 | +COMMENT ON COLUMN weather.created_by IS 'User that created the record'; |
| 44 | +COMMENT ON COLUMN weather.created_at IS 'Datetime when the record was created'; |
| 45 | +COMMENT ON COLUMN weather.updated_by IS 'Last user that updated the record'; |
| 46 | +COMMENT ON COLUMN weather.updated_at IS 'Last timestamp when the record was updated'; |
0 commit comments