May 2018
Intermediate to advanced
576 pages
30h 25m
English
Let's create two randomly populated tables, of which one is large:
CREATE TABLE dish( dish_id SERIAL PRIMARY KEY, dish_description text);CREATE TABLE eater( eater_id SERIAL, eating_date date, dish_id int REFERENCES dish (dish_id));INSERT INTO dish (dish_description)VALUES ('Lentils'), ('Mango'), ('Plantain'), ('Rice'), ('Tea');INSERT INTO eater(eating_date, dish_id)SELECT floor(abs(sin(n)) * 365) :: int + date '2014-01-01', ceil(abs(sin(n :: float * n))*5) :: intFROM generate_series(1,500000) AS rand(n);
Notice that the data is not truly random. It is generated by a deterministic procedure, so you get exactly the same result if you copy the preceding code.