Home > database >  How would you create a decimal sequence in postgresql?
How would you create a decimal sequence in postgresql?

Time:03-04

What I'm trying to do is populate a table with data such as follows:

| thickness | length | width  |
|: 0.02 |:1:| 1:|
|: 0.02 |:1:| 2:|
|: 0.04|:1:|1:|
|: 0.06|:1:| 1:|

Essentially I have a column thickness that I need populated from 0 to 10 in increments of 0.02

My Width and Length columns similarly need to be populated from 1 to 144 in increments of 0.02

This is large number of rows and would like to populate it automaticly instead of typing this all out by hand. Unfortunately I could only get the sequence to work as integers, and I would like them to increment by decimals. THANK YOU!

CodePudding user response:

You can use a cross join between two generate_series() calls

insert into the_table (thickness, length, width)
select t.thickness, l.val, l.val
from generate_series(0,10,0.02) as t(thickness) 
  cross join generate_series(1,144,0.02) as l(val)
  • Related