Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kYXmc-0000U1-OV for pgsql-admin@arkaria.postgresql.org; Fri, 30 Oct 2020 17:01:46 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1kYXmb-00071L-FO for pgsql-admin@arkaria.postgresql.org; Fri, 30 Oct 2020 17:01:45 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kYXmb-00071E-4c for pgsql-admin@lists.postgresql.org; Fri, 30 Oct 2020 17:01:45 +0000 Received: from mail-ej1-x62f.google.com ([2a00:1450:4864:20::62f]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1kYXmU-0003g5-Gr for pgsql-admin@postgresql.org; Fri, 30 Oct 2020 17:01:44 +0000 Received: by mail-ej1-x62f.google.com with SMTP id p5so9586420ejj.2 for ; Fri, 30 Oct 2020 10:01:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cybertec-at.20150623.gappssmtp.com; s=20150623; h=message-id:subject:from:to:date:in-reply-to:references:user-agent :mime-version:content-transfer-encoding; bh=gbBtUaqLVJ7A1a7MGOm817xxVFempdNLp+C1CZ9vSHo=; b=Xhx9//T5EmqB9oMm9/x2AjTBdwtJaMjmuojy2cQe+XOgj1Zg4loc7yyYULuaHpOSd5 eogYZlel1vwCoJRWnzBzXTpYXYSABV3W62LU8mJdZ2pAPaTUNZBiZHcMb3+nICLGOzKf cDSnVSw5VjnDLgiUoCgCEu3EHOZhXCzTFNWIe+TXpkfxKqToDJm1xbrjmaDePQBUl28f 67iHFUj7+2KYuvN156yHoz69dIcE11gko6ySLxHdrbQB0v457skfwou6VsY2kC7MCDLa Nh/SxGYzIZsc/X/VDZkoXX0WwiFbjyyYF0//8UEXXXMKb66NcNvTsni6vTsInCijP/Hj Ccqw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:message-id:subject:from:to:date:in-reply-to :references:user-agent:mime-version:content-transfer-encoding; bh=gbBtUaqLVJ7A1a7MGOm817xxVFempdNLp+C1CZ9vSHo=; b=dGf2fAlxDZ2CL8lHR5MYytGqDL7+TItXZPE2ATlQG/rM3VIcHtSN1qC/pEAdyNuegi RqK0EL9/nzl8IlUa3SvZDg9PR+hrx7gZijSWiXeYfHc8B5+OUvaQ58pQD9gsCpcYBTv2 IIdkiNzv94T4JaZSH2No1aZzkhCkDHVPT4JVQIQV6Z/ibJOxffbN0KemcOtwtBPY+SwB 7PwezgUm53TpTWg9RFNWkod1Y37NDgMnSLmS4INXFwlU3YvY+lI8K4ZNZ5u3GqBSZYNf ZVg6Q9/5WM8IelBQAmZ/3O1vrjugja/r6t4N//vKHRX0saSehSO/0M+kdYdP1wKAnSZ1 BIUQ== X-Gm-Message-State: AOAM532f93LU7jyMen3OFQXMRo6px5GGV0yYz7CV7jB7nYLlCeHL+eNo +SnbpOeaowDwvV6mzMLw/7qYqQ== X-Google-Smtp-Source: ABdhPJzd0XXfMl6hFqp9kSOawnhnx3FvPYUjrijJ+SNVefN/8kJBdcgwlC/xXWfmFfT9DDSaLGPlMA== X-Received: by 2002:a17:907:392:: with SMTP id ss18mr3474498ejb.429.1604077296646; Fri, 30 Oct 2020 10:01:36 -0700 (PDT) Received: from localhost.localdomain (217-149-171-152.nat.highway.telekom.at. [217.149.171.152]) by smtp.gmail.com with ESMTPSA id k1sm3369712edl.0.2020.10.30.10.01.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 30 Oct 2020 10:01:36 -0700 (PDT) Message-ID: <8cf7a01702a3dae1205e5dcf09b27e083dcd9511.camel@cybertec.at> Subject: Re: Creating a partition table From: Laurenz Albe To: John Scalia , pgsql-admin Date: Fri, 30 Oct 2020 18:01:35 +0100 In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" User-Agent: Evolution 3.36.5 (3.36.5-1.fc32) MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On Fri, 2020-10-30 at 12:52 -0400, John Scalia wrote: > I have a PostgreSQL server version 11.3 that my devs are asking for some partitioned tables. I can’t seem to get the syntax correct though. My SQL code is: > > CREATE TABLE schema.temp_table > AS (SELECT * FROM schema.original_table) > PARTITION BY LIST(attribute_name); > > As what I want to do is create a copy of the current table, create the partitions on the new temp table, and when everything works, drop the original table and do an alter table rename on the new > one. > > The error is: > ERROR: syntax error at or near “PARTITION” > Line 3: PARTITION BY LIST(attribute_name); > > I’ve tried using the word RANGE as opposed to LIST, but the error remains. Does PostgreSQL not support a construct like this one or am I doing something wrong? You cannot do that in a single step. For one, you didn't create partitions. Do it like this: CREATE TABLE temp_table (LIKE original_table INCLUDING ALL) PARTITION BY LIST(attribute_name); CREATE TABLE temp_table_1 PARTITION OF temp_table FOR VALUES IN (1); CREATE TABLE temp_table_2_3 PARTITION OF temp_table FOR VALUES IN (2, 3); INSERT INTO temp_table SELECT * FROM original_table; Yours, Laurenz Albe -- Cybertec | https://www.cybertec-postgresql.com