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 1pyROp-0004eu-09 for pgsql-admin@arkaria.postgresql.org; Mon, 15 May 2023 06:09:35 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1pyROn-0001ft-OR for pgsql-admin@arkaria.postgresql.org; Mon, 15 May 2023 06:09:33 +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 1pyROn-0001fj-EH for pgsql-admin@lists.postgresql.org; Mon, 15 May 2023 06:09:33 +0000 Received: from mail-yb1-xb2c.google.com ([2607:f8b0:4864:20::b2c]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1pyROg-002oqa-OJ for pgsql-admin@lists.postgresql.org; Mon, 15 May 2023 06:09:32 +0000 Received: by mail-yb1-xb2c.google.com with SMTP id 3f1490d57ef6-ba716790926so4395534276.2 for ; Sun, 14 May 2023 23:09:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1684130965; x=1686722965; h=content-transfer-encoding:in-reply-to:from:references:to :content-language:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=DJTkWMHooWOZiv+7x7kLGkHC+/2284IPZgS8GHYDl7E=; b=o14nHDR4yJC6UBd7AUdslSruNf3cruz5fer+ALKq23CUfO2rmPsAYYlBTOEhqv8urL wXrEGFz+Cguj3TsWqYzjpwoIdGX13eVXYw1eAXNS0dlr4KLEOoSdm9bMLJZ8z5gY2Ffl GHtrKjIMXOEPCWD0qtuhqADiB8I33tYJhLNMUPfK7tHTLqc9ZB0g/JN/kOWBJ/5eoX2/ as8pKwwljFJM5fggdnaQdFk6/WFYhh23v5wTig/NTnbMHyHnWvUs9AN4wzpv/s2UfHQO gmlW47dGsR1FnExoj0PMLbK40d2jFJrEJcoP0Ud82uf/TMxrrMGVO0wUacuf5oXfr7KZ 7ALg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684130965; x=1686722965; h=content-transfer-encoding:in-reply-to:from:references:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=DJTkWMHooWOZiv+7x7kLGkHC+/2284IPZgS8GHYDl7E=; b=LE5hNehQAZwJI/cpmHNvAeaHvun4m/iL2NKuw3ChRPf4fAzavDqxqpni/nDCakwnUF MbAjiesFS+s/DI4brNl+I1Sd4auBawDEmSg7RJkmpFoUA7bnD84XowAX5H9BdGfKxVUH 0Ght5FrUQK9LLsLjWX1HQgsvW5En10nFkrNQfH+mXJ2q1OzTqs44waxLIzh2pSMN9b12 gtrzm4KJpjUAom092VBjPyKfGFb+Tcy2vHMwFdVp3wvgNEb9TlOHen5WtAgq2cmL3yJ8 Y8BOGvZJkyQZSEFSyOUCFHOQm5G6csIUIf2SRT8soZXN0IqhL/yxIrioA1SeHrbzPn2L NdSw== X-Gm-Message-State: AC+VfDwGpzFP9RDM/ft/9JXKvjYEIb2HgeuCJWLgpUpo3Jwpug+1vTlF fGGqdlPWI90T0hYTpwt0by+Tr+3dbnw= X-Google-Smtp-Source: ACHHUZ5tdA4VM9IeC0OM9Q/aO9Gz/OQHod2fbmW0yPZc8VU2evIvyEehzbwXbX/8MsFzbU0iJlspbQ== X-Received: by 2002:a25:c701:0:b0:b92:2b28:3461 with SMTP id w1-20020a25c701000000b00b922b283461mr27143069ybe.0.1684130965188; Sun, 14 May 2023 23:09:25 -0700 (PDT) Received: from ?IPV6:2600:1700:bd2c:b810:80f6:4741:9863:ef90? ([2600:1700:bd2c:b810:80f6:4741:9863:ef90]) by smtp.googlemail.com with ESMTPSA id n188-20020a2540c5000000b00b9eeffa1abfsm1722526yba.39.2023.05.14.23.09.24 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 14 May 2023 23:09:24 -0700 (PDT) Message-ID: <34308ba9-6033-6e57-f44e-500b2ca9cad5@gmail.com> Date: Mon, 15 May 2023 01:09:24 -0500 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.10.0 Subject: Re: how do I capture conflicting rows Content-Language: en-US To: pgsql-admin@lists.postgresql.org References: From: Ron In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 5/15/23 00:32, Nikhil Ingale wrote: > Hi All, > > The following query inserts the rows by ignoring the rows that has conflicts. > > INSERT INTO test (id,name,age,branch) SELECT * FROM student ON CONFLICT DO > NOTHING; > > How do I capture the conflicting records to a file while non conflicting > records are inserted to the table? On conflict insert the PK into a separate table, along with a timestamp column populated by clock_timestamp().  (That way you can export and delete sets of records while it's being written to. -- Born in Arizona, moved to Babylonia.