Skip to Main Content
PostgreSQL 9 Administration Cookbook - Second Edition
book

PostgreSQL 9 Administration Cookbook - Second Edition

by Simon Riggs, GIANNI CIOLLI, Hannu Krosing, Gabriele Bartolini
April 2015
Intermediate to advanced content levelIntermediate to advanced
504 pages
11h 41m
English
Packt Publishing
Content preview from PostgreSQL 9 Administration Cookbook - Second Edition

Generating test data

DBAs frequently need to generate test data for a variety of reasons, whether it's for setting up a test database or just for generating a test case for a SQL performance issue.

How to do it…

To create a table of test data, we need the following:

  • Some rows
  • Some columns
  • Some order

The steps are as follows:

  1. First, generate a lot of rows of data. We use something named a "set-returning function". You can write your own, though PostgreSQL includes a couple of very useful ones.

    You can generate a sequence of rows using a query like the following:

    postgres=# SELECT * FROM generate_series(1,5);
     generate_series
    -----------------
                   1
                   2
                   3
                   4
                   5
    (5 rows)
    

    Alternatively, you can generate a list of dates, like this:

    postgres=# SELECT date(generate_series(now(), ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

PostgreSQL 10 Administration Cookbook - Fourth Edition

PostgreSQL 10 Administration Cookbook - Fourth Edition

Simon Riggs, Gianni Ciolli
Mastering PostgreSQL 10

Mastering PostgreSQL 10

Hans-Jürgen Schönig

Publisher Resources

ISBN: 9781849519069Supplemental Content