trdsql generate_series
generate_series
PostgreSQL has a convenient function called generate_series().
This function works similarly to the Unix seq command. generate_series() also has an extension that can be used with timestamp types.
The usage is simple. Specify the “start value”, “end value”, and “increment value (optional)” and execute.
generate_series() is a function that returns a table and can be used instead of a table.
(en: You can also write SELECT generate_series(1,10)).
Of course, trdsql can easily incorporate input from external sources, so you can also use the seq command as a substitute.
The order of arguments for the seq command is “start value”, “increment value (optional)”, “end value”.
Timestamp
generate_series() can handle timestamps, so it’s a bit tricky to output the 2020 calendar in Japanese, but it looks like this.
Increase the amount of data
There are times when you want a certain amount of dummy data. If you want completely distributed random data, you need to use a dedicated tool.
However, if you just want to increase the number of existing data, you can create it by CROSS JOINing generate_series() or the seq command.
Using the seq command, it looks like this.
(When processing a file with a header with -ih, the first line of seq is interpreted as a header, so starting from 0 will result in an extra line being output).