Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gzshC-0000yr-EC for pgsql-general@arkaria.postgresql.org; Sat, 02 Mar 2019 00:40:06 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1gzshB-0005Eu-5p for pgsql-general@arkaria.postgresql.org; Sat, 02 Mar 2019 00:40:05 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gzshA-00059j-Lw for pgsql-general@lists.postgresql.org; Sat, 02 Mar 2019 00:40:04 +0000 Received: from mail-pl1-x633.google.com ([2607:f8b0:4864:20::633]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gzsh8-00009S-7q for pgsql-general@lists.postgresql.org; Sat, 02 Mar 2019 00:40:03 +0000 Received: by mail-pl1-x633.google.com with SMTP id c17so9069403plz.13 for ; Fri, 01 Mar 2019 16:40:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:to:references:from:message-id:date:user-agent:mime-version :in-reply-to:content-language; bh=+sb/yYk2McVlwinDmX2N+kTGhvGl0C1AAVJaDf0Q8mQ=; b=YGe5k4uyoPvc5PClR0QJyInta1S6DgKpdl+H61MDLk9UQ5/SDNu8jMNPnRgqpmIWE4 g53CKPvcOToXu49WUDOcokrECztHfqneTj0xMWJidtQWW6vSexNzI0+w/+x8+DOqzHzl xzxx4bcKapwfo5HECTuTHiOAclgVL4YBILXNfHLpZaRSu0hU3+AkMuUIvdhcCvXoqtu8 9ZEjTgjAS2F+67WBp5299HqJZpDBduDG/T9C/scWiv9LjloCxKBJegrQhur9lR2Q7xWL xD2k+qm8Pw8hFtpMayobowgooDs+I8wV/taWdx+Tu/jy7m+9+NxX7vdXsLkd2518XfVK pzkQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language; bh=+sb/yYk2McVlwinDmX2N+kTGhvGl0C1AAVJaDf0Q8mQ=; b=Je54w8tIElShlIbDUUyLVUSzcJgJFBG5trWviwx6UE40dx8pPmJ8Dwi5pii+Q2RynF m+mIQi2u4xXtmU0gaYzSAOjQusNvUXZfKYvFcT/Z151wn3+xfI0dfQs8oRoPR/aHcUmK e0fMjQkfldTJibrWo9T6AJlM1HrwuTlHQujXu19fl9ST7vSscIhLX9pS+gybZCne4oBO CB4VL75YoVBy0fVxNu+LatYij68g+Wrd4kFlcQoG04BAcrN9bjWloOF4CBCIM5KVTacZ PFm8UpV4WpjrG/HFDLuvmG8DvgM2ja6UISn357pJDNZ5X2bK2P0fJSPVQVzyHQBobXqB zhNQ== X-Gm-Message-State: APjAAAWu0E/A7Nd5x0hEGM1lugXTQdeu9Oow47RHsInPaYoZxj/y2FCO v6XAKTIKvqiGKJRrZgSccQfVs5zT X-Google-Smtp-Source: APXvYqzm7IqfeFZYDWqmLqTyvKfgvkw0Q3Rkq/sJu7Z2+KVeh7o83Q5sf05XCBImz8+y1JHOpNYM9w== X-Received: by 2002:a17:902:6804:: with SMTP id h4mr8409150plk.115.1551487200815; Fri, 01 Mar 2019 16:40:00 -0800 (PST) Received: from [10.0.0.102] (c-73-223-6-106.hsd1.ca.comcast.net. [73.223.6.106]) by smtp.gmail.com with ESMTPSA id t10sm55516922pfa.151.2019.03.01.16.39.58 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 01 Mar 2019 16:40:00 -0800 (PST) Subject: how best to specify table constraints with "create table as " To: pgsql-general@lists.postgresql.org References: From: Kevin Wilkinson Message-ID: <39455b88-04a5-ea0c-1016-16132b15d838@gmail.com> Date: Fri, 1 Mar 2019 16:39:53 -0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:60.0) Gecko/20100101 Thunderbird/60.5.1 MIME-Version: 1.0 In-Reply-To: Content-Type: multipart/alternative; boundary="------------718E6D851A04371CEC602F91" Content-Language: en-US List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk This is a multi-part message in MIME format. --------------718E6D851A04371CEC602F91 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit 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 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 --------------718E6D851A04371CEC602F91--