'How to insert a for loop in a CREATE TABLE statement?
I have the following SQL:
CREATE TABLE test(
"col1" text NOT NULL,
"col2" text,
do $$
begin
for cnt in 0..10 loop
"person.position."+ values(cnt) +".tarif" text,
"brief.person.position"+ values(cnt) +".text" text,
"brief.person.position." + values(cnt) + ".year" year,
"brief.person.position." + values(cnt) + ".rechnungsbetrag" float,
"brief.person.position." + values(cnt)+ ".leistung" text
end loop;
end; $$;
);
but it throws me an syntax error at the do...
What I want to achieve is that the table is created with the 11 defined "dynamic values" and two columns, but my syntax doesn't work like that.
This is for PostgreSQL if it matters.
I have no idea how to insert this for loop in the create table statement, help is very much appreciated.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
