Skip to content

Instantly share code, notes, and snippets.

@bvaradar
Last active October 27, 2020 22:29
Show Gist options
  • Save bvaradar/f0e9c25cfaa54262972ec8e8cec05afd to your computer and use it in GitHub Desktop.
Save bvaradar/f0e9c25cfaa54262972ec8e8cec05afd to your computer and use it in GitHub Desktop.
Debezium Load Generation
CREATE TABLE temp_20200817(
id integer PRIMARY KEY,
temp_id integer,
temp_status VARCHAR(16),
update_type VARCHAR(14),
price numeric(16,8),
quantity numeric,
timestamp timestamp,
seqno integer,
ts timestamp,
val date,
execution_id VARCHAR(32),
uuid uuid,
exec_temp VARCHAR(4),
account_id integer,
route VARCHAR(16),
temp_fee numeric(10,2),
vvv_fee numeric(10,2),
price_corrected_at timestamp
);
import sys
num_times=int(sys.argv[1])
start_val=int(sys.argv[2])
val = start_val;
for i in range(num_times):
print("SELECT insert_50K({0});".format(val))
#print("SELECT pg_sleep(1);")
val = val + 50000
CREATE Function insert_50K(start_val integer) RETURNS VOID AS
$$
declare
i int;
res int;
begin
for i in 1..50000
loop
insert into temp_20200817 (
id, temp_id, temp_status, update_type, price, quantity,
timestamp, seqno, ts, val, execution_id, uuid,
exec_temp, account_id, route, temp_fee, vvv_fee, price_corrected_at
)
select
i + start_val,
i + start_val,
'Fill',
'Fill',
random() * 10 + 1,
random() * 10 + 1,
CURRENT_TIMESTAMP,
i,
CURRENT_TIMESTAMP,
CURRENT_DATE,
md5(random()::text),
uuid_generate_v4(),
left(md5(i::text), 4),
i,
'wolverine',
random() * 10 + 1,
random() * 10 + 1,
CURRENT_TIMESTAMP;
end loop;
RAISE NOTICE 'Finished inserting 5000 records';
end;
$$
LANGUAGE plpgsql VOLATILE
COST 500;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment