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 1l1pPQ-000061-1C for pgsql-admin@arkaria.postgresql.org; Tue, 19 Jan 2021 11:42:52 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1l1pPO-00058o-Sp for pgsql-admin@arkaria.postgresql.org; Tue, 19 Jan 2021 11:42:50 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1l1pPO-00058h-Jh for pgsql-admin@lists.postgresql.org; Tue, 19 Jan 2021 11:42:50 +0000 Received: from lana.depesz.com ([88.198.49.178] helo=depesz.com) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1l1pPM-00052x-Ph for pgsql-admin@postgresql.org; Tue, 19 Jan 2021 11:42:50 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=depesz.com; s=20170201; h=In-Reply-To:Content-Transfer-Encoding:Content-Type: MIME-Version:References:Reply-To:Message-ID:Subject:Cc:To:Sender:From:Date: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=HxBBse9Mbn2UlMibFJ6wYIS7VbnlR594nXvYaJRpWkQ=; b=TSiFm7ShCeNTk41BzlhJLA4HpY 686R6MT3aYnOswZqEu5M6jUdu9QwXbfRk7uJv5FnVMmu2o8sOr8JakF0ixIoZ/iOcAy1GWnjOcOPs 0vABdRxgaN4hfW1I0HqjhrFoYQ8P9G8+KuxwVhyOPzf5XmHwcWQjupCxkIAOKO2lsL00=; Received: from lana.depesz.com ([88.198.49.178] helo=depesz.com) by depesz.com with esmtpa (Exim 4.92) (envelope-from ) id 1l1pPL-0008CZ-0W; Tue, 19 Jan 2021 12:42:47 +0100 Date: Tue, 19 Jan 2021 12:42:46 +0100 From: hubert depesz lubaczewski Sender: depesz@depesz.com To: Anjul Tyagi Cc: pgsql-admin Subject: Re: Table Partitioning Message-ID: <20210119114246.GA13372@depesz.com> Reply-To: depesz@depesz.com References: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: User-Agent: Mutt/1.10.1 (2018-07-13) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On Tue, Jan 19, 2021 at 10:21:27AM +0000, Anjul Tyagi wrote: > Hi All, > We are using postgres 10.12 and we have one table that size is more then 20Gb. We are planning to do the range partition on that > table, as we have date filed that can be used. We are able to create partition and it work fine, however one scenario where we are > getting error.  > We have created the yearly range for the partition, however we have some scenario where we have to update the date column and > respective record need to move from other child tables.  > For ex: > Table X has 3 partition X2019, X2020, X2021. Column is action_date, that we are using for partitioning.  > insert one record in X2019 and action date = 2019-11-16 > however now i have to update the date form '2019-11-16' to '2020-02-18', when we try to runt he Update statement, it give me an > error called "SQL-23514 - new row for relation X2019 violates partition constraint". > Can you please suggest, how can we handle that scenario? Do I have to write the trigger in Update statement and move the record > manually or perform the insert and delete operation.  The simplest solution would be to delete the rows, and immediately insert into appropriate partition. for example: with q as (delete * from x where action = '2019-11-16 returning *) insert into x select other, columns, '2020-02-18' from q; depesz