4
2

More than 5 years have passed since last update.

Prestoで100万レコードを生成するクエリ

Posted at

Presto(に関わらず)で、何百万レコードのデータをとりあえず出力したいときがある。
例えば、100万件からある機能が使えるようになるとか使えないとかそんなのをチャチャッと確かめたいとか。

そんな時は下記のクエリを実行する。

SELECT ones.n + 10*tens.n + 100*hundreds.n + 1000*thousands.n + 10000*tensthousands.n + 100000*hundredsthousands.n
FROM (VALUES(0),(1),(2),(3),(4),(5),(6),(7),(8),(9)) ones(n),
     (VALUES(0),(1),(2),(3),(4),(5),(6),(7),(8),(9)) tens(n),
     (VALUES(0),(1),(2),(3),(4),(5),(6),(7),(8),(9)) hundreds(n),
     (VALUES(0),(1),(2),(3),(4),(5),(6),(7),(8),(9)) thousands(n),
     (VALUES(0),(1),(2),(3),(4),(5),(6),(7),(8),(9)) tensthousands(n),
     (VALUES(0),(1),(2),(3),(4),(5),(6),(7),(8),(9)) hundredsthousands(n)
ORDER BY 1

すると、100万件が生成される。

4
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
2