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 1pyWBW-0004A2-F7 for pgsql-admin@arkaria.postgresql.org; Mon, 15 May 2023 11:16:10 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1pyWBU-0005lH-JM for pgsql-admin@arkaria.postgresql.org; Mon, 15 May 2023 11:16:08 +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 1pyWBT-0005l7-RK for pgsql-admin@lists.postgresql.org; Mon, 15 May 2023 11:16:08 +0000 Received: from wout2-smtp.messagingengine.com ([64.147.123.25]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1pyWBN-002rg2-Ai for pgsql-admin@lists.postgresql.org; Mon, 15 May 2023 11:16:07 +0000 Received: from compute2.internal (compute2.nyi.internal [10.202.2.46]) by mailout.west.internal (Postfix) with ESMTP id B5E6E3200900; Mon, 15 May 2023 07:15:57 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute2.internal (MEProxy); Mon, 15 May 2023 07:15:57 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:content-type:date:date:feedback-id:feedback-id :from:from:in-reply-to:in-reply-to:message-id:mime-version :reply-to:sender:subject:subject:to:to:x-me-proxy:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm1; t=1684149357; x= 1684235757; bh=SAcHT4ArYJ48abo4L1IEhVWfNEzFPqvpskWVW64N6Z8=; b=L sJcARR0heQM40Klh6QkpG2H0MCNJdvfZCYeLwKI3XaFqsy6Uin/5Gu1WLnev5fzl VrOhq8ZpGeBCfALrBtCcGAEviE6+kt35Kba7fFg3mHBTfu4MXKsNAyDZhYZJxJ0f nyZ1bF4X7Le+kOj7+nA9aduJ9+UgEhdijHhOPKLQblHQ80DDflSdNu+NnCLUBgLy djb/I5//3UI2JNmbnG1ioL47hE3LhBjZXK4J0lNGpVd8pF7e3/JJAm0C07oqawj5 6Kv4EBeKUhTjXSjlAEpOFk8oQvinvPiJzJ7DsoJKEMirMCw/rZw92zC/eQ3Rxc87 mZkc1uarIavHDvYYhVy1A== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvhedrfeehjedgfeelucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpeffhffvvefukfggtggugfgjsehtke ertddttdejnecuhfhrohhmpeetlhhvrghrohcujfgvrhhrvghrrgcuoegrlhhvhhgvrhhr vgesrghlvhhhrdhnohdqihhprdhorhhgqeenucggtffrrghtthgvrhhnpedvkedtffduff dtffffheffhfejjefhgfeiueeukeejkeffgfdufffhudffffeuveenucffohhmrghinhep vghnthgvrhhprhhishgvuggsrdgtohhmnecuvehluhhsthgvrhfuihiivgeptdenucfrrg hrrghmpehmrghilhhfrhhomheprghlvhhhvghrrhgvsegrlhhvhhdrnhhoqdhiphdrohhr gh X-ME-Proxy: Feedback-ID: ia2694551:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Mon, 15 May 2023 07:15:56 -0400 (EDT) Received: by perhan.alvh.no-ip.org (Postfix, from userid 1000) id E9461149; Mon, 15 May 2023 13:15:54 +0200 (CEST) Date: Mon, 15 May 2023 13:15:54 +0200 From: Alvaro Herrera To: Nikhil Ingale Cc: pgsql-admin@lists.postgresql.org Subject: Re: how do I capture conflicting rows Message-ID: <20230515111554.2a2q3hg2b4s5l7wh@alvherre.pgsql> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 2023-May-15, 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? It sounds like you want a new feature: INSERT INTO test (...) SELECT * FROM student ON CONFLICT EXECUTE FUNCTION do_your_stuff(excluded); Sounds like it could be useful, but somebody would have to design it fully and implement it. Or maybe just INSERT INTO test (...) SELECT * FROM student ON CONFLICT DO NOTHING RETURNING excluded.*; -- Álvaro Herrera PostgreSQL Developer — https://www.EnterpriseDB.com/ "Now I have my system running, not a byte was off the shelf; It rarely breaks and when it does I fix the code myself. It's stable, clean and elegant, and lightning fast as well, And it doesn't cost a nickel, so Bill Gates can go to hell."