-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDatabase_Draft.sql
More file actions
38 lines (31 loc) · 1.11 KB
/
Database_Draft.sql
File metadata and controls
38 lines (31 loc) · 1.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
-- Exported from QuickDBD: https://www.quickdatabasediagrams.com/
-- NOTE! If you have used non-SQL datatypes in your design, you will have to change these here.
CREATE TABLE "stations" (
"id" varchar NOT NULL,
"station_name" varchar NOT NULL,
"longitude" numeric(7,4) NOT NULL,
"latitude" numeric(7,4) NOT NULL,
CONSTRAINT "pk_stations" PRIMARY KEY (
"id"
)
);
CREATE TABLE "weather" (
"serialid" int NOT NULL,
"id" varchar NOT NULL,
"date_str" date NOT NULL,
"degrees_from_mean" numeric(5,2) NOT NULL,
"max_temp" numeric(4,1) NOT NULL,
"min_temp" numeric(4,1) NOT NULL,
"type" varchar(100) NOT NULL,
CONSTRAINT "pk_weather" PRIMARY KEY (
"serialid","id"
)
);
ALTER TABLE "weather" ADD CONSTRAINT "fk_weather_id" FOREIGN KEY("id")
REFERENCES "stations" ("id");
SELECT w.serialid, w.id, w.date_str, w.degrees_from_mean, w.max_temp, w.min_temp, w.type,
s.station_name, s.longitude, s.latitude, DATE_PART('YEAR', w.date_str) AS year
INTO data
FROM weather w
INNER JOIN nc_stations s
USING (id);