-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathinit.sql
More file actions
44 lines (39 loc) · 1.24 KB
/
init.sql
File metadata and controls
44 lines (39 loc) · 1.24 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
CREATE TABLE public.fruit (
id serial4 NOT NULL,
"name" varchar NULL,
fruityvice_id int4 NULL
);
CREATE TABLE public."location" (
id serial4 NOT NULL,
"name" varchar NULL,
headcount varchar NULL
);
CREATE TABLE public.ledger (
fruit_id varchar NOT NULL,
location_id int4 NOT NULL,
amount int4 NULL,
"time" timestamptz NOT NULL
);
INSERT INTO public."fruit" ("name", "fruityvice_id") VALUES
('Lime', 44),
('Tangerine', 77),
('Apple', 6),
('Mango', 27),
('Plum', 71),
('Pineapple', 10),
('Kiwi', 665),
('Pear', 4);
INSERT INTO public."location" ("name", "headcount") VALUES
('Amsterdam', 200),
('Berlin', 100),
('Paris', 20),
('London', 50);
INSERT INTO public.ledger (fruit_id, location_id, amount, time)
SELECT
floor(random() * 7 + 1)::int AS fruit_id, -- Random fruit_id from 1 to 8
floor(random() * 3 + 1)::int AS location_id, -- Random location_id from 1 to 4
(floor(random() * 10) - 3)::int AS amount, -- Random amount from -1000 to 1000
timestamp '2016-01-01 00:00:00' +
random() * (extract(epoch from timestamp '2024-04-23 00:00:00' - timestamp '2016-01-01 00:00:00')) * interval '1 second'
AS time -- Random timestamp between 2016 and now
FROM generate_series(1, 500);