-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSchemaSetup.sql
More file actions
84 lines (52 loc) · 1.36 KB
/
SchemaSetup.sql
File metadata and controls
84 lines (52 loc) · 1.36 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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
--Drop database if already created
DROP DATABASE IF EXISTS stocksdb;
--create database
CREATE DATABASE stocksdb;
--drop tables if already in database
DROP TABLE IF EXISTS Prices;
DROP TABLE IF EXISTS Fundamentals;
DROP TABLE IF EXISTS Securities;
--Create Tables
CREATE TABLE Prices (
tdate DATE NOT NULL,
symbol TEXT NOT NULL,
open NUMERIC,
close NUMERIC,
low NUMERIC,
high NUMERIC,
volume INTEGER,
PRIMARY KEY(tdate, symbol)
);
CREATE TABLE Fundamentals (
id INTEGER PRIMARY KEY,
symbol TEXT NOT NULL,
year_ending DATE,
cash_and_cash_equiv BIGINT,
earning_bf_interest_and_tax BIGINT,
gross_margin INTEGER,
net_income BIGINT,
total_assets NUMERIC,
total_liability NUMERIC,
total_revenue NUMERIC,
year INTEGER,
earnings_per_share NUMERIC,
shares_outstanding NUMERIC
);
CREATE TABLE Securities (
symbol TEXT PRIMARY KEY,
company TEXT NOT NULL,
sector TEXT,
sub_industrial TEXT,
it_date DATE
);
--add values to tables
\COPY Prices FROM './data/prices.csv/' WITH (FORMAT csv);
\COPY Fundamentals FROM './data/fundamentals.csv/' WITH (FORMAT csv);
\COPY Securities FROM './data/securities.csv/' WITH (FORMAT csv);
\pset footer off
\echo '\nPrices Table.\n'
SELECT * FROM Prices WHERE symbol <> 'WLTW' LIMIT 20 ;
\echo 'Fundamentals Table.\n'
SELECT * FROM Fundamentals LIMIT 20;
\echo 'Securities Table.\n'
SELECT * FROM Securities LIMIT 20;