From: Kevin Wilkinson <w.kevin.wilkinson@gmail.com>
To: pgsql-general@lists.postgresql.org
Subject: how best to specify table constraints with "create table as <query>"
Date: Fri, 1 Mar 2019 16:39:53 -0800
Message-ID: <39455b88-04a5-ea0c-1016-16132b15d838@gmail.com> (raw)
In-Reply-To: <CANrrCRxLYcoXw_VWD10jEYCAwYb-wX8AKSFxe8vaFDUHpnYS_Q@mail.gmail.com>
References: <CANrrCRxLYcoXw_VWD10jEYCAwYb-wX8AKSFxe8vaFDUHpnYS_Q@mail.gmail.com>
i want to recluster an immutable table without locking the table and
then add the table as a partition of a parent table. my plan was:
create table tbl_cpy as select * from tbl order by c1 asc;
alter table tbl_cpy add constraint c1 not null, c1>=lo c1<hi;
alter table tbl_parent attach partition tbl_cpy for values from (lo)
to (hi);
i want this to run quickly. so, i populate the table with a parallel
query (using create table as ...). i do NOT want attach partition to
rescan the table (which it does to validate the value range) so i have
to explicitly add constraints to tbl_cpy. but adding these constraints
itself causes a scan of the table.
so, i want to specify the constraints when the table is created. but
that seems not possible. if i first create an empty table with
constraints, then i cannot populate it with a parallel query (since
insert into is not parallel).
am i missing something? any ideas?
thanks,
kevin
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-general@postgresql.org
Cc: w.kevin.wilkinson@gmail.com
Subject: Re: how best to specify table constraints with "create table as <query>"
In-Reply-To: <39455b88-04a5-ea0c-1016-16132b15d838@gmail.com>
References: <CANrrCRxLYcoXw_VWD10jEYCAwYb-wX8AKSFxe8vaFDUHpnYS_Q@mail.gmail.com> <39455b88-04a5-ea0c-1016-16132b15d838@gmail.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox