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 1hHAQ6-0003vb-MB for pgsql-general@arkaria.postgresql.org; Thu, 18 Apr 2019 17:01:55 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1hHAQ5-0002Lp-6R for pgsql-general@arkaria.postgresql.org; Thu, 18 Apr 2019 17:01:53 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hHAQ3-0002DP-U1 for pgsql-general@lists.postgresql.org; Thu, 18 Apr 2019 17:01:52 +0000 Received: from out4-smtp.messagingengine.com ([66.111.4.28]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hHAQ0-00078s-D5 for pgsql-general@lists.postgresql.org; Thu, 18 Apr 2019 17:01:51 +0000 Received: from compute6.internal (compute6.nyi.internal [10.202.2.46]) by mailout.nyi.internal (Postfix) with ESMTP id 16DD727D2B; Thu, 18 Apr 2019 13:01:47 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute6.internal (MEProxy); Thu, 18 Apr 2019 13:01:47 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=aklaver.com; h= subject:to:references:from:message-id:date:mime-version :in-reply-to:content-type:content-transfer-encoding; s=fm2; bh=d GDf6qYkiYY4I9ZxMCmM0998BDOkONmYPpE3xTkfBvA=; b=GC9F6Zejwi0IK0RyF hb9TuEMNl8XabOs6WekjKNc6Ee9jecrfQxvUvxRePYhNsXaHXtbtk4sst1beskaZ IYNXC9fXceRH1qHL9Q5Dfy9aryllKuWE/aD/79Eo0YUTZMuou0LMZP8fUvaY/MbH yewb1YinyDJ//blaCNCewQ7VpT3bL3h7tI5n64yScwk+U+WMSzNoc9kQ7dAfALX1 meqBvL62QM4csppVxocK5SfQucr/F8cJBxv9g7V0NBa7U+vDdLSAguoNSkI0lIOA wDoR02yIB1RL2Oe3JJraV9YIzzz2V0ZAwcxPa4AQiOk62MRLVuL2rZQMeww+IUSM Fd1gA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:references :subject:to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender :x-sasl-enc; s=fm2; bh=dGDf6qYkiYY4I9ZxMCmM0998BDOkONmYPpE3xTkfB vA=; b=vml1+u+4oc/4oa1Lv5Ws5MLo1pltZu66nVPrgcbCzm5qjNpza7kIK+dvf +bxdZkEk7BRDxe9HMheymUqOD8cIkRj9Yd1N6yT7g7p1PAYdiasdOBGhedpaTYZT F0/zdBONaSPlYwBYo1jt7H7Tn2y1b/Itz7Or2X+H/pZjzDKt0ps+UEp/+dK3QBwA rCKG0SoAE0AA2neqe7tKzK8VUiXvk+/Ab1qkgtxgq+cdIhiMjmmv5VTbHdXeWziL iKsZLNBSODvJ4WMTkqFIRICRcEQCCwXVWlzbqkrn5jXLrw2CqCIiCHBg0Zyw5WD3 am8qF5PPkTnx2ku9UBatQeA2hOTHg== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeduuddrfeehgdegjecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenuc fjughrpefuvfhfhffkffgfgggjtgfgsehtkeertddtfeejnecuhfhrohhmpeetughrihgr nhcumfhlrghvvghruceorggurhhirghnrdhklhgrvhgvrhesrghklhgrvhgvrhdrtghomh eqnecukfhppeejgedrleefrddutdehrddukeeinecurfgrrhgrmhepmhgrihhlfhhrohhm pegrughrihgrnhdrkhhlrghvvghrsegrkhhlrghvvghrrdgtohhmnecuvehluhhsthgvrh fuihiivgeptd X-ME-Proxy: Received: from ranger.suse (74-93-105-186-washington.hfc.comcastbusiness.net [74.93.105.186]) by mail.messagingengine.com (Postfix) with ESMTPA id 1F5CAE43A3; Thu, 18 Apr 2019 13:01:45 -0400 (EDT) Subject: Re: SQL query To: Vikas Sharma , pgsql-general@lists.postgresql.org References: From: Adrian Klaver Message-ID: <401f56ab-894c-dc50-bf16-08cfe262ddf7@aklaver.com> Date: Thu, 18 Apr 2019 10:01:44 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.6.1 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On 4/18/19 9:43 AM, Vikas Sharma wrote: > Hi, > > I have come across a query that a developer wrote to update a few rows > in table, the query did update the two desired rows but also updated the > rest of the table with the column value as 'false'. > > Update tableA set col1 = null and col2 in (1,2); > > The query updated col1 to null for the rows where col2 was either 1 or > 2, rest of rows were also updated for col1 to 'false'. >  The above was run without where clause. > Could the experts throw some light on this? Hmm. What Postgres version? Assuming col1 is boolean, correct? My experimentation: create table up_test(id integer, col1 boolean, col2 integer); insert into up_test values (1, 't', 1), (2, null, 2), (3, 't', 4); update up_test set col1=null and col2 in(1,2); UPDATE 3 select * from up_test; id | col1 | col2 ----+------+------ 1 | | 1 2 | | 2 3 | f | 4 (3 rows) truncate up_test ; TRUNCATE TABLE insert into up_test values (1, 't', 1), (2, null, 2), (3, 't', 4); INSERT 0 3 update up_test set col1=(null and col2 in(1,2)); UPDATE 3 test_(postgres)# select * from up_test; id | col1 | col2 ----+------+------ 1 | | 1 2 | | 2 3 | f | 4 Looks to me it is seeing the and as part of an expression. > > Regards > Vikas Sharma -- Adrian Klaver adrian.klaver@aklaver.com