-
Notifications
You must be signed in to change notification settings - Fork 699
/
03-Techniques-Load.sql
32 lines (24 loc) · 1.15 KB
/
03-Techniques-Load.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
-- https://www.pg4e.com/lectures/03-Techniques-Load.sql
-- Start fresh - Cascade deletes it all
DELETE FROM account;
ALTER SEQUENCE account_id_seq RESTART WITH 1;
ALTER SEQUENCE post_id_seq RESTART WITH 1;
ALTER SEQUENCE comment_id_seq RESTART WITH 1;
ALTER SEQUENCE fav_id_seq RESTART WITH 1;
INSERT INTO account(email) VALUES
INSERT INTO post (title, content, account_id) VALUES
( 'Dictionaries', 'Are fun', 3), -- [email protected]
( 'BeautifulSoup', 'Has a complex API', 1), -- [email protected]
( 'Many to Many', 'Is elegant', (SELECT id FROM account WHERE email='[email protected]' ));
INSERT INTO comment (content, post_id, account_id) VALUES
( 'I agree', 1, 1), -- dict / ed
( 'Especially for counting', 1, 2), -- dict / sue
( 'And I don''t understand why', 2, 2), -- dict / sue
( 'Someone should make "EasySoup" or something like that',
(SELECT id FROM post WHERE title='BeautifulSoup'),
(SELECT id FROM account WHERE email='[email protected]' )),
( 'Good idea - I might just do that',
(SELECT id FROM post WHERE title='BeautifulSoup'),
(SELECT id FROM account WHERE email='[email protected]' ))
;