PostgreSQL - Write loop that creates new tables based on select query
0
votes
1
answer
2159
views
In concept this is simple. I'm constructing a new database. I have all of the tables I want to create in tb.table_build and I want to write a statement that creates new tables for each of the items in the table_build select query.
DO $$
DECLARE counterVariable integer;
CounterMax Varchar(150);
begin
for Countermax in (select table_name
from table_build
where build_type = 'Number')
loop
CREATE TABLE Countermax (
LIKE template_text_input);
end loop;
end;
$$;
I cannot pass the variable CounterMax into the Create Table statement.
Asked by J Taylor
(1 rep)
Apr 29, 2022, 04:55 AM
Last activity: Feb 14, 2025, 04:02 PM
Last activity: Feb 14, 2025, 04:02 PM