Skip to content

Instantly share code, notes, and snippets.

@okabe-yuya
Created March 9, 2023 01:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save okabe-yuya/256df0f1b59bdcd6ab956200577141b0 to your computer and use it in GitHub Desktop.
Save okabe-yuya/256df0f1b59bdcd6ab956200577141b0 to your computer and use it in GitHub Desktop.
検証データの詳細

table

BEGIN;
  CREATE TABLE IF NOT EXISTS users (
    user_id SERIAL PRIMARY KEY,
    user_name VARCHAR(50) NOT NULL
  );
  CREATE TABLE IF NOT EXISTS products (
    product_id SERIAL PRIMARY KEY,
    product_name VARCHAR(50) NOT NULL
  );
  CREATE TABLE IF NOT EXISTS user_products (
    user_product_id SERIAL PRIMARY KEY,
    user_id INTEGER,
    product_id INTEGER,
    FOREIGN KEY (user_id) REFERENCES users(user_id),
    FOREIGN KEY (product_id) REFERENCES products(product_id)
  );
COMMIT;

insert

BEGIN;
  INSERT INTO users(user_name) SELECT format('ユーザーNo.%s', i) FROM generate_series(1, 10000) as i;
  INSERT INTO products(product_name) SELECT format('プロダクトNo.%s', i) FROM generate_series(1, 10000) as i;
  INSERT INTO user_products(user_id, product_id) SELECT i, i FROM generate_series(1, 10000) as i;
COMMIT;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment