-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsql_statements.sql
More file actions
61 lines (46 loc) · 1.51 KB
/
Copy pathsql_statements.sql
File metadata and controls
61 lines (46 loc) · 1.51 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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
-- changing the wal level for the connector debezium
ALTER SYSTEM SET wal_level = logical;
show wal_level;
-- create the schema
create schema dev;
-- create the table users
CREATE TABLE dev.users (
id SERIAL PRIMARY KEY,
name VARCHAR(100),
creation_date DATE
);
-- or you can create the table users with the following schema to avoid entering dates
CREATE TABLE your_table_name (
id SERIAL PRIMARY KEY,
name VARCHAR(255) NOT NULL,
creation_date TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
-- insert the first so the topic would auto created by the connector
INSERT INTO dev.users (name, creation_date) VALUES ('jane doe','2022-01-23');
--
-- Inject more data into the table -----------
-- Generate sample names
WITH sample_names AS (
SELECT 'John' AS name UNION ALL
SELECT 'Jane' AS name UNION ALL
SELECT 'Mike' AS name UNION ALL
SELECT 'Emily' AS name UNION ALL
SELECT 'David' AS name UNION ALL
SELECT 'Sarah' AS name UNION ALL
SELECT 'Michael' AS name UNION ALL
SELECT 'Olivia' AS name UNION ALL
SELECT 'Daniel' AS name UNION ALL
SELECT 'Sophia' AS name
)
-- Insert data into the users table
INSERT INTO dev.users (name, creation_date)
SELECT
name,
current_date - (random() * 365)::integer AS creation_date
FROM sample_names
CROSS JOIN generate_series(1, 5);
--test an upsert statement to validate it won't be counted--
INSERT INTO dev.users (id, name, creation_date)
VALUES (1, 'judy', '2022-01-01')
ON CONFLICT (id)
DO UPDATE SET name = EXCLUDED.name, creation_date = EXCLUDED.creation_date;