Reputation: 687
I want to insert a series of numbers in a postgreSQL column.The series will be
1,1,1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,2,2,3,3,3,3,3,3,3,3,3.....30
So 1-30 repeated 10 times each(300 rows).but I know to generate series I can use
SELECT a.n
from generate_series(1, 100) as a(n), generate_series(1, 3)
How to insert this series into an existing table public.trip and to the column day.I tried with
update public.trip
set day = generate_series(1, 30) , generate_series(1, 10);
But this is showing as an error.Any help is appreciated.
Upvotes: 1
Views: 3519
Reputation: 118
If you are inserting it as new data then you should use an INSERT INTO statement i this case it will be (I am assuming a.n is where the value of day is contained)
INSERT INTO public.trip(Day)
SELECT a.n from generate_series(1, 100) as a(n), generate_series(1, 3)
if you are updating an existing record then you can use the UPDATE statement
UPDATE public.trip SET Day = SELECT a.n from generate_series(1, 100) as a(n), generate_series(1, 3) WHERE [condition]
I hope this help
Upvotes: 6