views:

46

answers:

2

Hello.

I have a table with two fields:

  1. id(uuid) that is primaryKey and
  2. description (var255)

I want to insert random data with sql sentance. I would like that description would be something random.

Can some1 please help me with this?

PS: im using postgresql.

A: 

I assume sentance == statement? You could use perl or plperl as perl has some good random data generators. Check out perl CPAN module Data::Random to start.

Here's a sample of a perl script to generate some different random stuff taken from CPAN.

use Data::Random qw(:all);

  my @random_words = rand_words( size => 10 );

  my @random_chars = rand_chars( set => 'all', min => 5, max => 8 );

  my @random_set = rand_set( set => \@set, size => 5 );

  my $random_enum = rand_enum( set => \@set );

  my $random_date = rand_date();

  my $random_time = rand_time();

  my $random_datetime = rand_datetime();

  open(FILE, ">rand_image.png") or die $!;
  binmode(FILE);
  print FILE rand_image( bgcolor => [0, 0, 0] );
  close(FILE);
StarShip3000
A: 

I dont know exactly if this fits the requirement for a "random description", and it's not clear if you want to generate the full data: but, for example, this generates 10 records with consecutive ids and random texts:

  test=#  SELECT id, md5(random()::text) AS desc FROM
          (SELECT * FROM generate_series(1,10) AS id) AS x;
     id |               desc
    ----+----------------------------------
      1 | 65c141ee1fdeb269d2e393cb1d3e1c09
      2 | 269638b9061149e9228d1b2718cb035e
      3 | 020bce01ba6a6623702c4da1bc6d556e
      4 | 18fad4813efe3dcdb388d7d8c4b6d3b4
      5 | a7859b3bcf7ff11f921ceef58dc1e5b5
      6 | 63691d4a20f7f23843503349c32aa08c
      7 | ca317278d40f2f3ac81224f6996d1c57
      8 | bb4a284e1c53775a02ebd6ec91bbb847
      9 | b444b5ea7966cd76174a618ec0bb9901
     10 | 800495c53976f60641fb4d486be61dc6
    (10 rows)
leonbloy