Re: How to insert random character data into tables for testing purpose. THanks.

Lists: pgsql-general
From: leaf_yxj <leaf_yxj(at)163(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: How to insert random character data into tables for testing purpose. THanks.
Date: 2012-05-02 16:14:52
Message-ID: 1335975292838-5680973.post@n5.nabble.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-general

Hi Guys, I want to insert the random character data into tables for testing
purpose.
I created a table as follows :

create table test ( id int, b char(100));

I need to insert 100000 rows into this table. I know how to insert
generate_series into coloumn ID. But I don't how to insert the Random
string data into column b.

Please help. Thanks. Grace

--
View this message in context: http://postgresql.1045698.n5.nabble.com/How-to-insert-random-character-data-into-tables-for-testing-purpose-THanks-tp5680973.html
Sent from the PostgreSQL - general mailing list archive at Nabble.com.


From: Andreas Kretschmer <akretschmer(at)spamfence(dot)net>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: How to insert random character data into tables for testing purpose. THanks.
Date: 2012-05-02 16:32:14
Message-ID: 20120502163214.GA14413@tux
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-general

leaf_yxj <leaf_yxj(at)163(dot)com> wrote:

> Hi Guys, I want to insert the random character data into tables for testing
> purpose.
> I created a table as follows :
>
> create table test ( id int, b char(100));
>
> I need to insert 100000 rows into this table. I know how to insert
> generate_series into coloumn ID. But I don't how to insert the Random
> string data into column b.

something like:

test=# create table t_random as select s, md5(random()::text) from generate_Series(1,5) s;
SELECT 5
Time: 163,624 ms
test=*# select * from t_random ;
s | md5
---+----------------------------------
1 | ef82dcb3e8465fa9a7494c569dfa093f
2 | ad6ae62bb4a49c7889aba0bfcba224ff
3 | 27717d30d8cf069b3129853d90ae5035
4 | 530c200678711a414e000c60e73286bd
5 | 2b2c3692da1b60760ff95d41cdf9b82d
(5 rows)

Andreas
--
Really, I'm not out to destroy Microsoft. That will just be a completely
unintentional side effect. (Linus Torvalds)
"If I was god, I would recompile penguin with --enable-fly." (unknown)
Kaufbach, Saxony, Germany, Europe. N 51.05082°, E 13.56889°


From: leaf_yxj <leaf_yxj(at)163(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: How to insert random character data into tables for testing purpose. THanks.
Date: 2012-05-02 18:03:47
Message-ID: 1335981827565-5681242.post@n5.nabble.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-general

Hi Andreas,

Thanks a lot.

I tried those following , they work.

1) insert into test values ( generate_series(1,100000000000),
md5(random()::text));

2) create table t_random as select s, md5(random()::text) from
generate_Series(1,5) s;

Thanks.
Regards.

Grace

--
View this message in context: http://postgresql.1045698.n5.nabble.com/How-to-insert-random-character-data-into-tables-for-testing-purpose-THanks-tp5680973p5681242.html
Sent from the PostgreSQL - general mailing list archive at Nabble.com.


From: Bruce Momjian <bruce(at)momjian(dot)us>
To: leaf_yxj <leaf_yxj(at)163(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Re: How to insert random character data into tables for testing purpose. THanks.
Date: 2012-05-02 23:14:21
Message-ID: 20120502231421.GH8084@momjian.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-general

On Wed, May 02, 2012 at 11:03:47AM -0700, leaf_yxj wrote:
> Hi Andreas,
>
> Thanks a lot.
>
> I tried those following , they work.
>
> 1) insert into test values ( generate_series(1,100000000000),
> md5(random()::text));
>
>
> 2) create table t_random as select s, md5(random()::text) from
> generate_Series(1,5) s;

Here is a method that generates strings with a little more variability:

SELECT
(
SELECT string_agg(x, '')
FROM (
SELECT chr(ascii('A') + (random() * 25)::integer)
-- reference 'b' so it is correlated and re-evaluated
FROM generate_series(1, 40 + b * 0)
) AS y(x)
)
FROM generate_series(1,5) as a(b);

string_agg
------------------------------------------
JWNRUIEPJQGDVBXDJDTROFSNMKGVNAQWWEORMSHV
KNYGOWJXBEPOJICURIQGIIDFMRXYLFUUSTCIRLGR
PVHXEITVQKBZREFEVDDHHYCASEIKPOCFJJDNRWJJ
HKIYONDLQGSXFUXXZGHPUKUESXRLUATBLCAAPDLG
JEENYCLYISODDIGWGXHBYCCJECJTFUAOYECXGNWO
(5 rows)

--
Bruce Momjian <bruce(at)momjian(dot)us> http://momjian.us
EnterpriseDB http://enterprisedb.com

+ It's impossible for everything to be true. +


From: yxj <leaf_yxj(at)163(dot)com>
To: "Bruce Momjian" <bruce(at)momjian(dot)us>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Re: How to insert random character data into tables for testing purpose. THanks.
Date: 2012-05-03 15:23:50
Message-ID: 391833b2.12496.137134cd1a4.Coremail.leaf_yxj$163.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-general

Hi Bruce,

Thanks. I tried. It works.
Regards.

Grace

At 2012-05-03 07:14:21,"Bruce Momjian" <bruce(at)momjian(dot)us> wrote:
>On Wed, May 02, 2012 at 11:03:47AM -0700, leaf_yxj wrote:
>> Hi Andreas,
>>
>> Thanks a lot.
>>
>> I tried those following , they work.
>>
>> 1) insert into test values ( generate_series(1,100000000000),
>> md5(random()::text));
>>
>>
>> 2) create table t_random as select s, md5(random()::text) from
>> generate_Series(1,5) s;
>
>Here is a method that generates strings with a little more variability:
>
> SELECT
> (
> SELECT string_agg(x, '')
> FROM (
> SELECT chr(ascii('A') + (random() * 25)::integer)
> -- reference 'b' so it is correlated and re-evaluated
> FROM generate_series(1, 40 + b * 0)
> ) AS y(x)
> )
> FROM generate_series(1,5) as a(b);
>
> string_agg
> ------------------------------------------
> JWNRUIEPJQGDVBXDJDTROFSNMKGVNAQWWEORMSHV
> KNYGOWJXBEPOJICURIQGIIDFMRXYLFUUSTCIRLGR
> PVHXEITVQKBZREFEVDDHHYCASEIKPOCFJJDNRWJJ
> HKIYONDLQGSXFUXXZGHPUKUESXRLUATBLCAAPDLG
> JEENYCLYISODDIGWGXHBYCCJECJTFUAOYECXGNWO
> (5 rows)
>
>--
> Bruce Momjian <bruce(at)momjian(dot)us> http://momjian.us
> EnterpriseDB http://enterprisedb.com
>
> + It's impossible for everything to be true. +