2006-05-24

Generation of random test data

I need to generate data for testing of multicolumn GiST indices, for example, (date,integer).

postgres=# SELECT '1998-01-01'::DATE + (1000*random())::integer +generate_series(0,20), (1000*random())::integer+generate_series(0,20);
  ?column?  | ?column?
------------+----------
 2000-06-17 |      155
 1998-04-24 |      238
 1998-01-26 |      921
 2000-09-13 |      785
 1999-06-08 |      903
 1999-06-07 |      220
 1999-01-13 |      932
 1998-05-14 |      783
 1998-09-10 |      884
 1999-06-01 |       93
 1999-06-23 |      114
 1999-03-14 |      247
 1999-05-23 |      849

We need some random NULLs :) Use CASE

postgres=# select case when substr('123',1,1) = 1 then NULL else 'B' end;
 case
------

(1 row)

Final query: