In PostgreSQL you can use the random()
function to simulate such data without the need for an external language, with SQL only. 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 must have a different data range, such as precipitation in hundreds of millimeters, I imagine, and the presence of snakes in boolean "true" or "false."
The random()
function returns a random value of 0 to 1, so multiply by the maximum limit of the value in question. In addition to random()
, I used the floor()
function to round down the station random value and generate_series()
to build a hundred-register table, but I do not need the data it returns. All of this is passed to INSERT
that will populate 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 check 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 the steps: link