how to prepare a create table statement

From: Alexander Mills <alexander(dot)d(dot)mills(at)gmail(dot)com>
To: pgsql-bugs(at)lists(dot)postgresql(dot)org
Subject: how to prepare a create table statement
Date: 2021-01-04 04:46:19
Message-ID: CA+KyZp6SeL-ULK=jjquNcz23hb0nZXYa8wDW1sJJJ=xDiHicxw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

I am trying to create 500 partitions using a loop:

do $$
declare
counter integer := 0;
begin
while counter <= 500 loop
PREPARE create_table(int) AS
CREATE TABLE mbk_auth_method_$1 PARTITION OF mbk_auth_method FOR
VALUES WITH (modulus 500, remainder $1);
EXECUTE create_table (counter);
counter := counter + 1;
end loop;
end$$;

problem is that a CREATE TABLE cannot be prepared statement..

Anyone know how I can accomplish the above? Seems like this is a missing
feature - to prepare a CREATE TABLE statement..

--
Alexander D. Mills
New cell phone # (415)730-1805
linkedin.com/in/alexanderdmills

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Pavel Stehule 2021-01-04 10:51:03 Re: how to prepare a create table statement
Previous Message Michael Paquier 2021-01-03 06:21:09 Re: BUG #16801: Invalid memory access on WITH RECURSIVE with nested WITHs