Skip to content

Commit ccd54c4

Browse files
committed
add demo timestamp tables
1 parent 9da1c33 commit ccd54c4

File tree

1 file changed

+44
-3
lines changed

1 file changed

+44
-3
lines changed

demo/initdb/04-views.sql

Lines changed: 44 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,55 @@
11
CREATE TABLE cities (
2-
id serial PRIMARY KEY,
3-
name text,
2+
name text PRIMARY KEY,
43
geom geometry(Point, 4326)
54
);
65

6+
CREATE TABLE trips (
7+
id serial PRIMARY KEY,
8+
city text REFERENCES cities(name),
9+
time timestamptz,
10+
start_time timestamptz,
11+
end_time timestamptz
12+
);
13+
14+
CREATE TABLE receipts (
15+
id serial PRIMARY KEY,
16+
trip_id int REFERENCES trips(id),
17+
time timestamptz,
18+
amount numeric
19+
);
20+
21+
722
INSERT INTO cities (name, geom) VALUES
823
('Paris', ST_SetSRID(ST_MakePoint(2.3522, 48.8566), 4326)),
24+
('London', ST_SetSRID(ST_MakePoint(-0.1276, 51.5074), 4326)),
25+
('Tokyo', ST_SetSRID(ST_MakePoint(139.6917, 35.6895), 4326)),
26+
('Sydney', ST_SetSRID(ST_MakePoint(151.2093, -33.8688), 4326)),
927
('NYC', ST_SetSRID(ST_MakePoint(-74.0060, 40.7128), 4326));
1028

29+
30+
31+
INSERT INTO trips (city, time, start_time, end_time) VALUES
32+
('Paris', '2025-01-01 12:00:00', '2024-01-01 12:00:00', '2025-01-01 12:00:00'),
33+
('London', '2025-02-01 12:00:00', '2024-02-01 12:00:00', '2025-02-01 12:00:00'),
34+
('Tokyo', '2025-03-01 12:00:00', '2024-03-01 12:00:00', '2025-03-01 12:00:00'),
35+
('Sydney', '2025-04-01 12:00:00', '2024-04-01 12:00:00', '2025-04-01 12:00:00'),
36+
('NYC', '2025-05-01 12:00:00', '2024-05-01 12:00:00', '2025-05-01 12:00:00');
37+
38+
39+
INSERT INTO receipts (trip_id, time, amount) VALUES
40+
(1, '2024-06-01 12:00:00', 100.00),
41+
(1, '2024-07-01 12:00:00', 150.00),
42+
(2, '2024-06-15 12:00:00', 200.00),
43+
(3, '2024-08-01 12:00:00', 250.00),
44+
(4, '2024-09-01 12:00:00', 300.00),
45+
(5, '2024-10-01 12:00:00', 350.00);
46+
1147
-- View with geometry and featureID column (no PK)
1248
CREATE VIEW cities_view AS
13-
SELECT id AS id, name, geom FROM cities;
49+
SELECT * FROM cities;
50+
51+
CREATE VIEW trips_view AS
52+
SELECT trips.*, cities.geom FROM trips LEFT JOIN cities ON trips.city = cities.name;
1453

54+
CREATE VIEW receipts_view AS
55+
SELECT receipts.*, cities.geom FROM receipts LEFT JOIN trips ON receipts.trip_id = trips.id LEFT JOIN cities ON trips.city = cities.name;

0 commit comments

Comments
 (0)