In Postgresql you can use the function random()
to simulate such data without the need for an external language, only with SQL. I imagine it’s something easily transportable to other database systems.
First, I created a table with the specifications given in the question:
create table presenca_de_cobras (
precipitacao numeric(4,1) not null,
temperatura int not null,
presenca boolean not null,
estacao int not null,
constraint estacoes check (estacao in (1,2,3,4))
);
Each field should have a different data amplitude, such as precipitation in hundreds of millimeters, I imagine, and the presence of snakes in Boolean "true" or "false".
The function random()
returns a random value from 0 to 1, so multiply by the maximum limit of the value in question. In addition to random()
, I used the function floor()
to round down the random value of the season and the generate_series()
to build a table of a hundred records, but I don’t need the data it returns. All this is passed to INSERT
that will popularize the table:
-- insere os dados
insert into presenca_de_cobras
select
(random()*200)::numeric(4,1) precipitacao, -- precipitacao de 0-200 milimetros
(random()*40)::int temperatura, -- temperatura de 0-40 graus
(random() > 0.5) presenca, -- presenca TRUE ou FALSE
floor(random()*4+1)::int estacao -- estação de 1-4
from generate_series(1,100) as s;
Finally, just consult the table itself:
select * from presenca_de_cobras limit 10;
| precipitacao | temperatura | presenca | estacao |
|--------------|-------------|----------|---------|
| 137.2 | 16 | false | 4 |
| 164.5 | 38 | false | 3 |
| 4.3 | 14 | true | 3 |
| 134.9 | 38 | false | 2 |
| 3.9 | 18 | false | 3 |
| 67.3 | 37 | false | 1 |
| 140.3 | 34 | true | 3 |
| 34.2 | 35 | true | 4 |
| 56.3 | 37 | true | 1 |
| 171.5 | 5 | true | 4 |
Follow SQL Fiddle with all steps: http://sqlfiddle.com/#! 17/693a3/31/0
Ta, but what do you need help with ??... Want to know the most viable database ? How to do it ? What will you need ? Your question is a little vague...
– Dev
want to know how do script to build the data, when I have no data :|
– Maria Lopes