Skip to content

Instantly share code, notes, and snippets.

@henrytseng
Created January 3, 2019 03:53
Show Gist options
  • Save henrytseng/983fc8178300fe118231ea3037829952 to your computer and use it in GitHub Desktop.
Save henrytseng/983fc8178300fe118231ea3037829952 to your computer and use it in GitHub Desktop.
Quick SQL to build tables with example data
-- Creates list of bookings
create table bookings as
with
date_table as (select now()::date - generate_series(0, 7 * 10000) as date),
hour_table as (select generate_series(0, 24) as hour),
time_table as (
select
date_table.date::date as date,
extract(year from date_table.date) as year,
extract(month from date_table.date) as month,
extract(day from date_table.date) as day,
hour_table.hour
from date_table CROSS JOIN hour_table
)
SELECT
floor(random() * 100 + 1)::int as product_id,
date,
year,
month,
day,
hour
from time_table;
-- Creates list of product.id
create table products as
select generate_series(1,100) as id;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment