I have a pgscript that runs in a loop.
SET @id = 1;
BEGIN
WHILE @id <= 10
/*
CREATE TABLE tbl_name AS
SELECT * FROM main_tbl
WHERE id = @id
;
INSERT INTO tbl_name
SELECT * FROM main_tbl
WHERE id = @id
*/
SET @id = @id + 1;
END
For the first iteration id=1
, I want my script to create a table because the table does not exist. For the upcoming loop id=2...3...4...so on
, I want the script to insert into the table that was created.
Currently, I am creating an empty table before running the PgScript. Is there a way to write a script that creates the table for the first loop and insert in the upcoming iterations?