forked from Dalgerok/Twitsenger
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreate.sql
9697 lines (9637 loc) · 798 KB
/
create.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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
--DROP SCHEMA IF EXISTS public CASCADE;
--CREATE SCHEMA public;
--ALTER USER postgres WITH PASSWORD '1321';
----
CREATE TABLE locations (
country varchar(100) ,
city varchar(100) ,
location_id SERIAL ,
CONSTRAINT pk_location PRIMARY KEY ( location_id ),
CONSTRAINT un_location UNIQUE (country, city)
);
--CREATE INDEX locations_index_location ON locations(country, city);
CREATE RULE no_delete_locations AS ON DELETE TO locations
DO INSTEAD NOTHING;
CREATE RULE no_update_locations AS ON UPDATE TO locations
DO INSTEAD NOTHING;
----
----
CREATE TYPE genders AS ENUM (
'Male',
'Female',
'Unspecified'
);
----
----
CREATE TYPE relationshipstatus AS ENUM (
'Married',
'Single',
'Engaged',
'In a civil partnership',
'In a domestic partnership',
'In an open relationship',
'It is complicated',
'Separated',
'Divorced',
'Widowed'
);
----
----
CREATE TABLE users (
first_name varchar(32) NOT NULL ,
last_name varchar(32) NOT NULL ,
birthday date NOT NULL ,
email varchar(100) NOT NULL ,
relationship_status relationshipstatus NOT NULL ,
gender genders NOT NULL ,
user_password varchar(64) NOT NULL ,
user_location_id integer DEFAULT NULL,
picture_url varchar(2000) DEFAULT NULL,
user_id SERIAL ,
CONSTRAINT pk_user PRIMARY KEY ( user_id ),
CONSTRAINT un_email UNIQUE ( email ),
CONSTRAINT fk_user_location FOREIGN KEY ( user_location_id ) REFERENCES locations( location_id ),
CONSTRAINT ch_user_birthday CHECK ((now() - (birthday)::timestamp with time zone) >= '13 years'::interval year),
CONSTRAINT good_email CHECK (email ~* '^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+[.][A-Za-z]+$')
);
--CREATE INDEX users_index_name ON users(first_name, last_name);
--CREATE INDEX users_index_user_location_id ON users(user_location_id);
CREATE OR REPLACE FUNCTION no_update_user_id()
RETURNS TRIGGER AS
$$
BEGIN
IF NEW.user_id != OLD.user_id THEN
NEW.user_id = OLD.user_id;
END IF;
RETURN NEW;
END;
$$
LANGUAGE plpgsql;
CREATE TRIGGER no_update_user_id BEFORE UPDATE ON users
FOR EACH ROW EXECUTE PROCEDURE no_update_user_id();
CREATE FUNCTION check_password(
_email varchar,
_user_password varchar
)
RETURNS BOOLEAN AS
$$
BEGIN
RETURN EXISTS (
SELECT *
FROM users
WHERE users.email = _email AND users.user_password = _user_password
);
END;
$$
LANGUAGE plpgsql;
CREATE FUNCTION check_email(
_email varchar
)
RETURNS BOOLEAN AS
$$
BEGIN
RETURN EXISTS (
SELECT *
FROM users
WHERE users.email = _email
);
END;
$$
LANGUAGE plpgsql;
----
----
CREATE TABLE friendship (
friend1 integer NOT NULL ,
friend2 integer NOT NULL ,
CONSTRAINT pk_friendship PRIMARY KEY ( friend1, friend2 ),
CONSTRAINT fk_friendship_user1 FOREIGN KEY ( friend1 ) REFERENCES users( user_id ) ON DELETE CASCADE,
CONSTRAINT fk_friendship_user2 FOREIGN KEY ( friend2 ) REFERENCES users( user_id ) ON DELETE CASCADE,
CONSTRAINT ch_friendship CHECK (friend1 <> friend2)
);
--CREATE INDEX friendship_index_friend1 ON friendship(friend1);
CREATE RULE no_update_friendship AS ON UPDATE TO friendship
DO INSTEAD NOTHING;
CREATE OR REPLACE FUNCTION check_delete_friendship()
RETURNS TRIGGER AS
$$
BEGIN
IF EXISTS (
SELECT *
FROM friendship f
WHERE f.friend1 = OLD.friend2 AND f.friend2 = OLD.friend1
) THEN
DELETE FROM friendship f WHERE f.friend1 = OLD.friend2 AND f.friend2 = OLD.friend1;
END IF;
RETURN NULL;
END;
$$
LANGUAGE plpgsql;
CREATE TRIGGER check_delete_friendship AFTER DELETE ON friendship
FOR EACH ROW EXECUTE PROCEDURE check_delete_friendship();
CREATE OR REPLACE FUNCTION check_insert_friendship()
RETURNS TRIGGER AS
$$
BEGIN
IF NOT EXISTS (
SELECT *
FROM friendship f
WHERE NEW.friend1 = f.friend2 AND NEW.friend2 = f.friend1
) THEN
INSERT INTO friendship VALUES (NEW.friend2, NEW.friend1);
END IF;
RETURN NULL;
END;
$$
LANGUAGE plpgsql;
CREATE TRIGGER check_insert_friendship AFTER INSERT ON friendship
FOR EACH ROW EXECUTE PROCEDURE check_insert_friendship();
CREATE FUNCTION get_number_of_user_friends(id integer)
RETURNS integer
AS
$$
BEGIN
RETURN (
SELECT COUNT(*)
FROM friendship
WHERE friend1 = id
);
END;
$$
LANGUAGE plpgsql;
----
----
CREATE TABLE friend_request (
from_whom integer NOT NULL ,
to_whom integer NOT NULL ,
CONSTRAINT pk_friendrequest PRIMARY KEY ( from_whom, to_whom ),
CONSTRAINT fk_friendrequest_user1 FOREIGN KEY ( from_whom ) REFERENCES users( user_id ) ON DELETE CASCADE,
CONSTRAINT fk_friendrequest_user2 FOREIGN KEY ( to_whom ) REFERENCES users( user_id ) ON DELETE CASCADE,
CONSTRAINT ch_friendrequest CHECK (from_whom <> to_whom)
);
--CREATE INDEX friend_request_from_whom ON friend_request(from_whom);
CREATE RULE no_update_friend_request AS ON UPDATE TO friend_request
DO INSTEAD NOTHING;
CREATE OR REPLACE FUNCTION add_friend_request()
RETURNS TRIGGER AS
$$
BEGIN
IF EXISTS
(
SELECT *
FROM friend_request kek
WHERE NEW.from_whom = kek.to_whom AND NEW.to_whom = kek.from_whom
) THEN
DELETE FROM friend_request kek
WHERE NEW.from_whom = kek.to_whom AND NEW.to_whom = kek.from_whom;
INSERT INTO friendship
VALUES (NEW.from_whom, NEW.to_whom);
NEW = NULL;
END IF;
RETURN NEW;
END;
$$
LANGUAGE plpgsql;
CREATE TRIGGER insert_friend_request BEFORE INSERT ON friend_request
FOR EACH ROW EXECUTE PROCEDURE add_friend_request();
CREATE OR REPLACE FUNCTION check_friend_request()
RETURNS TRIGGER AS
$$
BEGIN
IF EXISTS
(
SELECT *
FROM friendship f
WHERE NEW.from_whom = f.friend1 AND NEW.to_whom = f.friend2
)
OR EXISTS
(
SELECT *
FROM friend_request fr
WHERE NEW.from_whom = fr.from_whom AND NEW.to_whom = fr.to_whom
)
THEN
NEW = NULL;
END IF;
RETURN NEW;
END;
$$
LANGUAGE plpgsql;
CREATE TRIGGER check_insert_friend_request BEFORE INSERT ON friend_request
FOR EACH ROW EXECUTE PROCEDURE check_friend_request();
----
----
CREATE TABLE messages (
user_from integer NOT NULL ,
user_to integer NOT NULL ,
message_text varchar(250) NOT NULL ,
message_date timestamp DEFAULT CURRENT_TIMESTAMP NOT NULL ,
message_id SERIAL ,
CONSTRAINT pk_message_id PRIMARY KEY ( message_id ),
CONSTRAINT fk_message_user1 FOREIGN KEY ( user_from ) REFERENCES users( user_id ) ON DELETE CASCADE,
CONSTRAINT fk_message_user2 FOREIGN KEY ( user_to ) REFERENCES users( user_id ) ON DELETE CASCADE,
CONSTRAINT ch_message CHECK (user_from <> user_to)
);
--CREATE INDEX messages_index_user_to ON messages(user_to);
--CREATE INDEX messages_index_user_from ON messages(user_from);
CREATE RULE no_update_message AS ON UPDATE TO messages
DO INSTEAD NOTHING;
CREATE FUNCTION get_latest_message(id1 integer, id2 integer) RETURNS integer AS
$$
BEGIN
RETURN (SELECT ms.message_id FROM messages ms
WHERE (ms.user_from = id1 AND ms.user_to = id2) OR (ms.user_from = id2 AND ms.user_to = id1) ORDER BY ms.message_date DESC LIMIT 1);
END;
$$
LANGUAGE plpgsql;
----
----
CREATE TABLE posts (
user_id integer NOT NULL,
post_text varchar(250) NOT NULL ,
post_date timestamp DEFAULT CURRENT_TIMESTAMP NOT NULL ,
reposted_from integer DEFAULT NULL,
post_id SERIAL ,
CONSTRAINT pk_post_id PRIMARY KEY ( post_id ),
CONSTRAINT fk_repost FOREIGN KEY ( reposted_from ) REFERENCES posts( post_id ) ON DELETE CASCADE,
CONSTRAINT fk_user_id FOREIGN KEY ( user_id ) REFERENCES users( user_id ) ON DELETE CASCADE
);
--CREATE INDEX posts_index_user_id ON posts(user_id);
CREATE RULE no_update_post AS ON UPDATE TO posts
DO INSTEAD NOTHING;
CREATE OR REPLACE FUNCTION check_insert_post_date()
RETURNS TRIGGER AS
$$
BEGIN
IF NEW.reposted_from IS NOT NULL AND (
SELECT posts.post_date
FROM posts
WHERE posts.post_id = NEW.reposted_from
) > NEW.post_date THEN
NEW = NULL;
END IF;
RETURN NEW;
END;
$$
LANGUAGE plpgsql;
CREATE TRIGGER check_insert_post BEFORE INSERT ON posts
FOR EACH ROW EXECUTE PROCEDURE check_insert_post_date();
CREATE FUNCTION get_number_of_user_posts(
id integer
)
RETURNS integer
AS
$$
BEGIN
RETURN (
SELECT COUNT(*)
FROM posts
WHERE user_id = id
);
END;
$$
LANGUAGE plpgsql;
CREATE FUNCTION get_user_posts(
id integer
)
RETURNS TABLE(
user_id integer,
post_text varchar(250),
post_date timestamp,
reposted_from integer,
post_id integer
)
AS
$$
BEGIN
RETURN QUERY (
SELECT *
FROM posts
WHERE posts.user_id = id
);
END;
$$
LANGUAGE plpgsql;
CREATE FUNCTION get_number_of_reposts_on_post(
id integer
)
RETURNS INTEGER
AS
$$
BEGIN
RETURN (
SELECT COUNT(*)
FROM posts
WHERE reposted_from = id
);
END;
$$
LANGUAGE plpgsql;
CREATE FUNCTION get_number_of_likes_on_post(
id integer
)
RETURNS INTEGER
AS
$$
BEGIN
RETURN (
SELECT COUNT(*)
FROM like_sign
WHERE post_id = id
);
END;
$$
LANGUAGE plpgsql;
DROP VIEW IF EXISTS get_refactored_all_posts;
CREATE VIEW get_refactored_all_posts
AS SELECT pp.*, kek.first_name, kek.last_name, kek.birthday,
kek.email, kek.relationship_status, kek.gender,
kek.user_password, kek.user_location_id, kek.picture_url, kek.user_id as "kek.user_id",
p.user_id as "p.user_id", p.post_text as "p.post_text",
p.post_date as "p.post_date", p.reposted_from as "p.reposted_from", p.post_id as "p.post_id",
us.first_name as "us.first_name", us.last_name as "us.lastname",
us.birthday as "us.birthday", us.email as "us.email",
us.relationship_status as "us.relationship_status",
us.gender as "us.gender", us.user_password as "us.user_password",
us.user_location_id as "us.user_location_id", us.picture_url as "us.picture_url",
get_number_of_likes_on_post(pp.post_id) as post_likes,
get_number_of_likes_on_post(p.post_id) as repost_likes
FROM posts pp
JOIN users kek ON pp.user_id = kek.user_id
LEFT JOIN posts p ON pp.reposted_from = p.post_id
LEFT JOIN users us ON p.user_id = us.user_id
ORDER BY pp.post_date DESC, pp.post_id DESC;
----
----
CREATE TABLE like_sign (
post_id integer NOT NULL ,
user_id integer NOT NULL ,
CONSTRAINT pk_like_sign PRIMARY KEY ( post_id, user_id ),
CONSTRAINT fk_like_sign_user_id FOREIGN KEY ( user_id ) REFERENCES users( user_id ) ON DELETE CASCADE,
CONSTRAINT fk_like_sign_post_id FOREIGN KEY ( post_id ) REFERENCES posts( post_id ) ON DELETE CASCADE
);
--CREATE INDEX like_sign_index_post_id ON like_sign(post_id);
CREATE RULE no_update_like_sign AS ON UPDATE TO like_sign
DO INSTEAD NOTHING;
----
----
CREATE TYPE facility_types AS ENUM (
'School',
'University',
'Work'
);
----
----
CREATE TABLE facilities (
facility_name varchar(100) NOT NULL,
facility_location integer NOT NULL,
facility_type facility_types NOT NULL,
facility_id SERIAL,
CONSTRAINT pk_facility_id PRIMARY KEY ( facility_id ),
CONSTRAINT fk_facility_location FOREIGN KEY ( facility_location ) REFERENCES locations( location_id ),
CONSTRAINT un_facility UNIQUE(facility_name, facility_location, facility_type)
);
--CREATE INDEX facilities_index_facility_type ON facilities(facility_type);
--CREATE INDEX facilities_index_facility_name ON facilities(facility_location);
--CREATE INDEX facilities_index_facility_location ON facilities(facility_location);
CREATE FUNCTION get_facilities_by_type(
type facility_types
)
RETURNS TABLE(
facility_name varchar(100),
facility_location integer,
facility_type facility_types,
facility_id integer
)
AS
$$
BEGIN
RETURN QUERY (
SELECT *
FROM facilities
WHERE facilities.facility_type = type
);
END;
$$
LANGUAGE plpgsql;
----
----
CREATE TABLE user_facilities (
user_id integer NOT NULL,
facility_id integer NOT NULL,
date_from timestamp NOT NULL,
date_to timestamp DEFAULT NULL,
description varchar(100),
CONSTRAINT pk_user_facility PRIMARY KEY ( user_id, facility_id, date_from ),
CONSTRAINT fk_user_facility_user_id FOREIGN KEY ( user_id ) REFERENCES users( user_id ) ON DELETE CASCADE,
CONSTRAINT fk_user_facility_facility_id FOREIGN KEY ( facility_id ) REFERENCES facilities( facility_id ),
CONSTRAINT ch_date CHECK ((date_to IS NULL) OR (date_to >= date_from))
);
--CREATE INDEX user_facilities_user_id ON user_facilities(user_id);
CREATE FUNCTION get_user_facilities(
id integer
)
RETURNS TABLE(
facility_name integer,
facility_type facility_types,
facility_country varchar(100),
facility_city varchar(100),
date_from timestamp,
date_to timestamp,
description varchar(100)
)
AS
$$
BEGIN
RETURN QUERY (
SELECT f.facility_name, f.facility_type, l.country, l.city, uf.date_from, uf.date_to, uf.description
FROM user_facilities uf
JOIN facilities f ON uf.facility_id = f.facility_id
JOIN locations l ON f.facility_location = l.location_id
WHERE uf.user_id = id
);
END;
$$
LANGUAGE plpgsql;
----
CREATE FUNCTION check_user_filter(
_user record,
fName varchar,
lName varchar,
_country varchar,
_city varchar,
fac_id integer,
datefrom timestamp,
dateto timestamp
)
RETURNS boolean
AS
$$
BEGIN
IF (_country IS NOT NULL AND _country != '') THEN
IF NOT EXISTS (
SELECT *
FROM locations
WHERE location_id = _user.user_location_id AND lower(country) LIKE '%'||lower(_country)||'%'
)THEN
RETURN FALSE;
END IF;
END IF;
IF (_city IS NOT NULL AND _city != '') THEN
IF NOT EXISTS(
SELECT *
FROM locations
WHERE location_id = _user.user_location_id AND lower(city) LIKE '%'||lower(_city)||'%'
) THEN
RETURN FALSE;
END IF;
END IF;
IF (fac_id IS NOT NULL AND fac_id != 0)THEN
IF (datefrom IS NULL)THEN
IF NOT EXISTS(SELECT * FROM user_facilities WHERE user_id = _user.user_id AND facility_id = fac_id)THEN RETURN FALSE; END IF;
ELSE
IF (dateto IS NULL)THEN dateto = NOW();END IF;
IF NOT EXISTS(SELECT * FROM user_facilities WHERE user_id = _user.user_id AND facility_id = fac_id AND
(NOT (date_from IS NOT NULL AND date_from > dateto)) AND (NOT (date_to IS NOT NULL AND date_to < datefrom)))THEN RETURN FALSE; END IF;
END IF;
END IF;
IF (lower(_user.first_name) LIKE '%'||lower(fName)||'%')THEN NULL;ELSE RETURN FALSE;END IF;
IF (lower(_user.last_name) LIKE '%'||lower(lName)||'%')THEN NULL;ELSE RETURN FALSE;END IF;
RETURN TRUE;
END;
$$
LANGUAGE plpgsql;
CREATE FUNCTION get_user_friends(
id integer
) RETURNS TABLE (
first_name varchar(100),
last_name varchar(100),
birthday date,
email varchar(254),
relationship_status relationshipstatus,
gender genders ,
user_password varchar(50),
user_location_id integer,
picture_url varchar(255),
user_id integer
)
AS
$$
BEGIN
RETURN QUERY (
SELECT *
FROM users
WHERE (id, users.user_id) IN (SELECT friend1, friend2 FROM friendship));
END;
$$
LANGUAGE plpgsql;
CREATE FUNCTION get_user_friends_with_user(
id integer
) RETURNS TABLE (
first_name varchar(100),
last_name varchar(100),
birthday date,
email varchar(254),
relationship_status relationshipstatus,
gender genders ,
user_password varchar(50),
user_location_id integer,
picture_url varchar(255),
user_id integer
)
AS
$$
BEGIN
RETURN QUERY (
SELECT *
FROM users
WHERE (id, users.user_id) IN (SELECT friend1, friend2 FROM friendship)
OR users.user_id = id
);
END;
$$
LANGUAGE plpgsql;
CREATE FUNCTION check_facility_filter(
_facility record,
facName varchar,
facType varchar
)
RETURNS boolean
AS
$$
BEGIN
IF (lower(_facility.facility_name) LIKE '%'||lower(facName)||'%') THEN NULL;ELSE RETURN FALSE;END IF;
IF (_facility.facility_type = facType::facility_types) THEN NULL;ELSE RETURN FALSE;END IF;
RETURN TRUE;
END;
$$
LANGUAGE plpgsql;
COPY locations (city, country) FROM stdin;
Tokyo Japan
New York United States
Mexico City Mexico
Mumbai India
São Paulo Brazil
Delhi India
Shanghai China
Kolkata India
Los Angeles United States
Dhaka Bangladesh
Buenos Aires Argentina
Karachi Pakistan
Cairo Egypt
Rio de Janeiro Brazil
Ōsaka Japan
Beijing China
Manila Philippines
Moscow Russia
Istanbul Turkey
Paris France
Seoul Korea, South
Lagos Nigeria
Jakarta Indonesia
Guangzhou China
Chicago United States
London United Kingdom
Lima Peru
Tehran Iran
Kinshasa Congo (Kinshasa)
Bogotá Colombia
Shenzhen China
Wuhan China
Hong Kong Hong Kong
Tianjin China
Chennai India
Taipei Taiwan
Bengalūru India
Bangkok Thailand
Lahore Pakistan
Chongqing China
Miami United States
Hyderabad India
Dallas United States
Santiago Chile
Philadelphia United States
Belo Horizonte Brazil
Madrid Spain
Houston United States
Ahmadābād India
Ho Chi Minh City Vietnam
Washington United States
Atlanta United States
Toronto Canada
Singapore Singapore
Luanda Angola
Baghdad Iraq
Barcelona Spain
Hāora India
Shenyang China
Khartoum Sudan
Pune India
Boston United States
Sydney Australia
Saint Petersburg Russia
Chittagong Bangladesh
Dongguan China
Riyadh Saudi Arabia
Hanoi Vietnam
Guadalajara Mexico
Melbourne Australia
Alexandria Egypt
Chengdu China
Rangoon Burma
Phoenix United States
Xi’an China
Porto Alegre Brazil
Sūrat India
Hechi China
Abidjan Côte D’Ivoire
Brasília Brazil
Ankara Turkey
Monterrey Mexico
Yokohama Japan
Nanjing China
Montréal Canada
Guiyang China
Recife Brazil
Seattle United States
Harbin China
San Francisco United States
Fortaleza Brazil
Zhangzhou China
Detroit United States
Salvador Brazil
Busan Korea, South
Johannesburg South Africa
Berlin Germany
Algiers Algeria
Rome Italy
Pyongyang Korea, North
\.
COPY users(first_name, last_name, birthday, email, relationship_status, gender, user_password, user_location_id) FROM stdin(FORMAT CSV);
Isaiah,Morris,1991-06-21,[email protected],It is complicated,Male,waOlfYpA0h6Uii8,52
Henry,Nguyen,1989-12-31,[email protected],Single,Male,&v%iUC4jCZo,75
Charlotte,Morgan,1975-11-22,[email protected],It is complicated,Female,#Y##fN7D1oiFVB,94
Christian,Phillips,1996-10-17,[email protected],In a domestic partnership,Male,Wr1WVNN30%uE,63
Alexander,Thomas,1992-04-23,[email protected],Widowed,Male,Ld#Nd^FV9,18
Aria,Peterson,1994-04-05,[email protected],Engaged,Female,ANP0KrxpPLk,70
Harper,Allen,2000-07-09,[email protected],Married,Female,6DTelQ8JfOe0OG1,67
Gabriel,Howard,1998-01-20,[email protected],Engaged,Male,8bZEFSt81v,4
Violet,Sanders,1979-06-21,[email protected],Married,Female,h0skiEw2G%nZDs,50
Olivia,Perez,1988-02-09,[email protected],In a domestic partnership,Female,Ewki98k&O8P,49
Aaliyah,Hill,1988-04-03,[email protected],Single,Female,hJI3N1vL,53
Allison,Gonzalez,1986-05-07,[email protected],Divorced,Female,VyT*VKyuLTDrr,17
Zoe,Miller,1980-07-19,[email protected],In an open relationship,Female,r&#lIc&$FfAH,85
John,Parker,1988-02-22,[email protected],Single,Male,6FFMrpm&gQqyd,100
Penelope,Wilson,1997-06-07,[email protected],Married,Female,mGYWKZEWx^yY,35
Ryan,Foster,1994-11-24,[email protected],Separated,Male,pBCTcABfhG,89
Christopher,Ward,1976-04-16,[email protected],Engaged,Male,xQECE&mtZ1&mn,98
Aiden,Cox,1996-01-22,[email protected],In a civil partnership,Male,p1*QHaBgz$,56
Chloe,Cooper,1990-03-06,[email protected],It is complicated,Female,7oTF3T58G3vv#,37
Joseph,Lopez,1979-07-13,[email protected],In an open relationship,Male,iM*H1XH6,72
Lillian,Turner,2000-04-14,[email protected],In a civil partnership,Female,&MyfOq8#dy,50
Owen,Scott,1976-07-12,[email protected],In an open relationship,Male,eyM$9SpvLoFC2,88
Leah,Brooks,1976-05-06,[email protected],In an open relationship,Female,fvWHzQ31TU,81
Elijah,Hughes,1994-10-23,[email protected],Married,Male,e&kJNuWqbj,6
Samantha,Rogers,2001-10-05,[email protected],Engaged,Female,%gY4#obrrN5,67
Noah,Long,1985-11-24,[email protected],Married,Male,%2FFwU1s,60
Nora,Bell,1991-09-09,[email protected],In an open relationship,Female,RYh7lhbz1i,32
Lucas,Collins,1998-01-25,[email protected],It is complicated,Male,k1KLrMevgD%ou#S,41
Julian,Watson,2002-09-07,[email protected],In a domestic partnership,Male,XvhMw$DQNKo1#qe,29
Andrew,Brown,2002-10-04,[email protected],Separated,Male,pElvtj261eYu,33
Audrey,Morales,1985-06-01,[email protected],In an open relationship,Female,tGw&URTDZIxn21o,97
Benjamin,Cook,1991-12-22,[email protected],Separated,Male,D$GgfHf*ak,29
Elizabeth,Lewis,1984-06-15,[email protected],In a civil partnership,Female,G3xsYr8z,11
Mason,King,1979-10-31,[email protected],Widowed,Male,1k#LjTgFNO,43
Daniel,Clark,1980-10-03,[email protected],Divorced,Male,gPvY&JXw2NdS,3
Carter,Kelly,1986-10-06,[email protected],In an open relationship,Male,4JoA0J%&6J2,93
Addison,Stewart,1976-07-28,[email protected],Separated,Female,nOHfrNTQt^F,93
Paisley,Smith,1979-04-09,[email protected],Separated,Female,mJb32W2ot,25
Anthony,Young,1976-04-01,[email protected],Single,Male,bQR&MZyd,15
David,Edwards,1983-01-10,[email protected],In an open relationship,Male,9EXdzF1mj12l,8
Avery,Ortiz,1993-05-12,[email protected],In a civil partnership,Female,uvyxjV^16S0wll,76
Madison,Roberts,1996-10-22,[email protected],In a civil partnership,Female,^hC#&XWnX8TD#c,65
Joshua,Adams,1993-10-18,[email protected],In an open relationship,Male,dDFd7LZkRgBY0V2,30
Riley,Moore,1976-02-02,[email protected],It is complicated,Female,qy3Ggef8JOk2u,88
Hunter,Sanchez,1997-01-09,[email protected],Divorced,Male,7npHNH4fM1LA,13
Sofia,Wright,1987-01-21,[email protected],In a civil partnership,Female,*IAYBx8YTNL,4
Landon,Baker,1998-09-08,[email protected],Engaged,Male,nQtqpJFoiVs&14N,86
Ethan,Richardson,1975-09-19,[email protected],Engaged,Male,sS*6%vFGzZJ,37
Jayden,Reed,2001-11-30,[email protected],It is complicated,Male,s5C&4#xksI41^C,46
Oliver,Ramirez,2001-02-04,[email protected],It is complicated,Male,yYtjY9HFT&aYsrN,93
Logan,Anderson,1991-02-05,[email protected],Separated,Male,PuY9HtZ9q72VH9,11
Ariana,Powell,2000-11-22,[email protected],In a domestic partnership,Female,J1912TeQ$$W#,5
Grayson,Nelson,1979-10-14,[email protected],Single,Male,gdULtJq00zQM,27
Samuel,Diaz,1986-07-21,[email protected],In a domestic partnership,Male,YTR%hjjgtV3Ca,5
Scarlett,Myers,1987-08-02,[email protected],Widowed,Female,Gykv6&FG85wK,31
Natalie,Harris,1982-08-07,[email protected],Engaged,Female,3SQVdVaPBF1,86
Emily,Campbell,1983-04-19,[email protected],In an open relationship,Female,pDrpsg1^W,81
Matthew,Gomez,1993-01-01,[email protected],In an open relationship,Male,PGFiS3Ey$f,59
Hannah,Price,1989-10-29,[email protected],Married,Female,JHJVsk1ZyFj,91
Lily,Barnes,1982-07-11,[email protected],Engaged,Female,cO5exvbJPM,25
Liam,Wood,1990-11-12,[email protected],Separated,Male,4J8u0BJYQRtDXd,24
Ellie,Rivera,1992-06-28,[email protected],In a civil partnership,Female,fuz7eorChX9,9
Emma,Flores,2000-09-06,[email protected],Divorced,Female,eZbV0cuZ0hGVOA,83
Victoria,Green,1995-11-05,[email protected],Divorced,Female,2SW^vtDdW7PNzWE,29
Brooklyn,Davis,1982-11-13,[email protected],Widowed,Female,riIW1A5obLNctw,27
Mia,Bailey,1991-12-24,[email protected],In a domestic partnership,Female,yWyNIiWKxsNfDjJ,43
Amelia,Johnson,1978-09-26,[email protected],Engaged,Female,va8#jugmhbR229R,60
Jack,Carter,1997-04-05,[email protected],Divorced,Male,hGB1%&177nijaL,77
Wyatt,Jenkins,1984-01-30,[email protected],In a domestic partnership,Male,j10H^X0z,51
Zoey,Evans,1996-08-18,[email protected],Engaged,Female,2qvifFGfB,43
Levi,Murphy,1984-11-26,[email protected],Divorced,Male,$qZB$SJO,53
Sophia,Sullivan,1992-01-07,[email protected],It is complicated,Female,vn&krTJFAh,60
Charles,Mitchell,1977-11-26,[email protected],Single,Male,rIeFxP1AE,21
Alexa,James,1987-02-27,[email protected],In a civil partnership,Female,zeAraD%evVH,59
Ava,Williams,1976-03-28,[email protected],Separated,Female,%Oq&uWdQS,53
Claire,Hall,1990-01-19,[email protected],Engaged,Female,wkH0Mv4n1Q,22
Jacob,Thompson,1998-10-01,[email protected],In an open relationship,Male,kWlIHvFVPcK1Si,65
Grace,Jackson,1979-06-25,[email protected],In a domestic partnership,Female,53bLHNsiMWjmwO*,100
Abigail,Jones,1984-12-28,[email protected],Engaged,Female,1xlctcJmZuVj*1r,19
Savannah,Taylor,2002-08-14,[email protected],It is complicated,Female,fTOfCR4Hapy,26
Isaac,Ross,1980-10-28,[email protected],It is complicated,Male,11X61u1L,54
Layla,Torres,1997-02-08,[email protected],Married,Female,Q#7fG%iFL,58
Caleb,Hernandez,1994-11-07,[email protected],In an open relationship,Male,vU*g$oYPS,86
Jonathan,Reyes,1983-11-29,[email protected],Single,Male,8GcssYxr*OM,6
Sebastian,Cruz,1990-10-14,[email protected],Engaged,Male,U0uxrguD9,2
James,Bennett,1994-11-22,[email protected],In a domestic partnership,Male,6Oq2xI43#u0ZqpM,43
Camila,Russell,1978-01-07,[email protected],Widowed,Female,1GRXj1Ov,79
Jackson,Lee,1986-10-08,[email protected],Single,Male,z&1#a$w#MR6eMq2,77
Jaxon,Martinez,1982-03-04,[email protected],Engaged,Male,YWI16CRXOQGCI0,27
William,Perry,1997-07-06,[email protected],Widowed,Male,0F2R1DbXX#jhLZ6,93
Isabella,Butler,1983-07-17,[email protected],Separated,Female,Cq1WSgXhQWdihG,64
Evelyn,Gray,1993-06-02,[email protected],In a domestic partnership,Female,65IaCD#^e,65
Nathan,Gutierrez,1986-09-11,[email protected],Married,Male,yqYUF4Efp$C,95
Aubrey,Robinson,1978-11-24,[email protected],In a civil partnership,Female,FW*Wlcd4nuG,77
Dylan,Walker,1985-03-28,[email protected],Separated,Male,$6Z8RBsc,25
Ella,Rodriguez,1999-07-27,[email protected],In an open relationship,Female,Tq%9%MoqzjiK1XE,70
Michael,White,1997-04-15,[email protected],In a domestic partnership,Male,8L1u8pixB&G^r,85
Luke,Fisher,1980-06-30,[email protected],Widowed,Male,&C1TO1R3F1BB,10
Skylar,Martin,1990-10-03,[email protected],In a civil partnership,Female,EC63AmoYTZz,30
Anna,Garcia,1997-05-29,[email protected],In a domestic partnership,Female,3o9T$mvqFJ8xvOp,42
\.
COPY friendship (friend1, friend2) FROM stdin(FORMAT CSV);
85,7
29,33
41,52
5,55
24,91
86,69
12,40
93,69
62,11
100,15
38,40
54,9
35,27
55,70
38,41
61,34
82,75
72,40
70,57
16,62
71,14
2,37
62,57
50,68
35,93
15,61
35,70
6,71
93,63
70,26
85,31
30,89
86,81
32,40
26,64
52,38
48,79
9,74
73,33
65,11
9,63
22,36
99,74
62,6
30,15
19,12
26,41
40,4
20,80
65,34
18,30
47,32
99,51
37,100
30,36
78,45
79,27
31,40
70,37
62,15
93,1
65,51
82,72
71,19
55,14
66,95
54,35
38,96
35,18
38,35
58,84
16,51
58,89
95,53
85,60
44,12
26,13
3,22
70,39
15,50
45,2
80,42
47,95
70,92
81,31
19,98
3,7
8,18
78,4
54,65
93,48
84,89
73,77
86,93
2,95
53,88
83,28
60,88
99,24
65,13
100,49
78,93
79,5
12,53
72,90
46,1
93,82
4,37
19,68
71,2
90,78
28,46
11,40
40,16
28,76
52,28
87,72
35,51
52,6
61,56
13,86
94,76
87,16
58,70
62,46
7,73
72,13
9,13
28,47
81,8
28,62
55,65
56,28
39,77
19,87
97,74
33,24
62,22
39,93
41,17
28,14
43,68
15,78
79,78
48,2
15,37
14,11
67,51
57,39
95,62
4,11
22,50
3,30
17,22
44,54
72,50
40,21
58,75
20,42
13,46
57,49
90,55
26,78
2,87
37,17
34,13
38,86
82,25
39,10
39,64
33,38
97,8
1,79
57,55
37,97
4,10