INSERT INTO in Postgresql with random values

Asked

Viewed 171 times

3

Hello.

My problem is basically a popular table in Postgresql with randomly generated data. As the SQL commands are quite extensive I would like to complement this table gradually. The table has the following structure:

------------------------------------------------------
| registro | nome |  CPF | localidade | cidade| email|
------------------------------------------------------

To fill the record column I used the following command:

INSERT INTO data SELECT generate_series(100000,999999) AS REGISTRO;

I could for example fill the first two columns with the following command:

INSERT INTO data SELECT generate_series(100000,999999) AS REGISTRO, md5(random()::text) AS NOME

However, as I said, my goal is to divide the commands into parts. I would then like a solution that based on filling the RECORD column I fill the NAME column. That is, if there is a data in RECORD then enter a data in name and so on.

I tried the following:

INSERT INTO data(nome) SELECT REGISTRO,  md5(random()::text) AS NOME;

But the following error occurs:

ERROR: column "name" of relation "data" does not exist

Someone knows a way around it?

  • It seems to be a problem for stored procedures, in which you can by conditionals and loops (pro case of popular)

1 answer

2

vc already populated your table the next step would be to change the column nome:

Update data set nome = md5(random()::text);

this will popular all the column rows nome with md5 Random text

  • That’s exactly what it was. About the error, I created the table in pgadmin3 with uppercase letters as well as the example shows, so the column name has to be referenced in the SQL command like this: "NAME", between quotation marks.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.