-
Notifications
You must be signed in to change notification settings - Fork 2
/
create_tables.sql
103 lines (95 loc) · 2.53 KB
/
create_tables.sql
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
-- This file defines all tables for the database
CREATE TABLE IF NOT EXISTS places (
place_id TEXT,
place_name TEXT,
place_country TEXT,
place_country_code TEXT,
place_full_name TEXT,
place_type TEXT,
place_street_address TEXT,
place_locality TEXT,
place_region TEXT,
place_iso3_country_code TEXT,
place_postal_code TEXT,
PRIMARY KEY(place_id)
);
CREATE TABLE IF NOT EXISTS place_bounding_box_coordinate (
id SERIAL,
place_id TEXT,
longitude DECIMAL,
latitude DECIMAL,
bound_type TEXT,
PRIMARY KEY(id),
FOREIGN KEY(place_id) REFERENCES places(place_id)
);
CREATE TABLE IF NOT EXISTS users (
user_id BIGINT,
user_screen_name TEXT,
user_name TEXT,
user_location TEXT,
user_description TEXT,
user_followers_count INT,
user_friends_count INT,
user_time_zone TEXT,
user_lang TEXT,
user_url TEXT,
user_geo_enabled BOOLEAN,
PRIMARY KEY(user_id)
);
CREATE TABLE IF NOT EXISTS user_relations (
follower_user_id BIGINT,
following_user_id BIGINT,
PRIMARY KEY(follower_user_id, following_user_id),
FOREIGN KEY(follower_user_id) REFERENCES users(user_id),
FOREIGN KEY(following_user_id) REFERENCES users(user_id)
);
CREATE TABLE IF NOT EXISTS tweets (
id BIGINT,
created_at TIMESTAMP,
text TEXT,
geo BOOLEAN,
user_id BIGINT,
longitude DECIMAL,
latitude DECIMAL,
geo_longitude DECIMAL,
geo_latitude DECIMAL,
place_id TEXT,
retweeted_id BIGINT,
original_tweet_retweet_count BIGINT,
in_reply_to_status_id BIGINT,
in_reply_to_user_id BIGINT,
lang TEXT,
detected_language TEXT,
PRIMARY KEY(id),
FOREIGN KEY(place_id) REFERENCES places(place_id),
FOREIGN KEY(user_id) REFERENCES users(user_id)
);
CREATE TABLE IF NOT EXISTS tweet_hashtags (
tweet_id BIGINT,
hashtag TEXT,
PRIMARY KEY(tweet_id, hashtag),
FOREIGN KEY(tweet_id) REFERENCES tweets(id)
);
CREATE TABLE IF NOT EXISTS geonames (
geonameid INT,
name VARCHAR (200),
asciiname VARCHAR (200),
alternatenames VARCHAR (10000),
latitude DECIMAL,
longitude DECIMAL,
feature_class CHAR(1),
feature_code VARCHAR (10),
country_code VARCHAR (2),
cc2 VARCHAR (200),
admin1_code VARCHAR (20),
admin2_code VARCHAR (80),
admin3_code VARCHAR (20),
admin4_code VARCHAR (20),
population BIGINT,
elevation INTEGER,
dem INTEGER,
timezone VARCHAR (40),
modification_date date
);
CREATE VIEW trumps_tweets AS
SELECT * FROM tweets WHERE user_id = 25073877;