-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtwitter_data.sql
53 lines (44 loc) · 1.91 KB
/
twitter_data.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
-- Twitter Example
-- requires twitter_tables.sql to have been run
begin;
set search_path to aphex_twitter,public;
-- create a couple users
insert into users (handle, name) values ('lizlemon', 'Liz Lemon');
insert into users (handle, name) values ('jack', 'Jack Donaghy');
insert into users (handle, name) values ('tracy', 'Tracy Jordan');
-- create some tweets for those users
insert into tweets (user_handle, content)
values ('lizlemon', 'Why are my arms so weak? It’s like I did that push-up last year for nothing!');
insert into tweets (user_handle, content)
values ('lizlemon', 'I love America. Just because I think gay dudes should be allowed to adopt kids and we should all have hybrid cars doesn’t mean I don’t love America.');
insert into tweets (user_handle, content)
values ('jack', 'There are no bad ideas, @lizlemon. Only good ideas that go horribly wrong.');
insert into tweets (user_handle, content)
values ('tracy', 'So, here’s some advice I wish I woulda got when I was your age: Live every week like it’s Shark Week.');
insert into tweets (user_handle, content)
values ('jack', 'Human empathy. It’s as useless as the Winter Olympics.');
insert into tweets (user_handle, content)
values ('tracy', 'Stop eating people’s old french fries, pigeon! Have some self respect! Don’t you know you can fly?');
select * from tweets;
select * from tweets where user_handle = 'lizlemon';
select id, user_handle from tweets;
-- id | user_handle
-- ----+-------------
-- 1 | lizlemon
-- 2 | lizlemon
-- 3 | jack
-- 4 | tracy
-- 5 | jack
-- 6 | tracy
-- pin some tweets
insert into pinned_tweets (tweet_id, user_handle)
select id, user_handle from tweets
where user_handle = 'lizlemon'
order by created_at desc
limit 1;
insert into pinned_tweets (tweet_id, user_handle)
select id, user_handle from tweets
where user_handle = 'jack'
order by created_at desc
limit 1;
select * from pinned_tweets;