Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1Y1j2H-0000CI-7t for pgsql-bugs@arkaria.postgresql.org; Thu, 18 Dec 2014 21:55:05 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1Y1j2G-0004Ke-MN for pgsql-bugs@arkaria.postgresql.org; Thu, 18 Dec 2014 21:55:04 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1Y1j2F-0004II-FN for pgsql-bugs@postgresql.org; Thu, 18 Dec 2014 21:55:03 +0000 Received: from outmail148161.authsmtp.com ([62.13.148.161]) by makus.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1Y1j2A-0006eT-VS for pgsql-bugs@postgresql.org; Thu, 18 Dec 2014 21:55:01 +0000 Received: from mail-c237.authsmtp.com (mail-c237.authsmtp.com [62.13.128.237]) by punt15.authsmtp.com (8.14.2/8.14.2/) with ESMTP id sBILsuM1067032; Thu, 18 Dec 2014 21:54:56 GMT Received: from alvin.alvh.no-ip.org (client-186-37-118-100.imovil.entelpcs.cl [186.37.118.100] (may be forged)) (authenticated bits=0) by mail.authsmtp.com (8.14.2/8.14.2/) with ESMTP id sBILsrWj035195; Thu, 18 Dec 2014 21:54:55 GMT Received: by alvin.alvh.no-ip.org (Postfix, from userid 1000) id E9EA01CA; Thu, 18 Dec 2014 18:54:58 -0300 (CLST) Date: Thu, 18 Dec 2014 18:54:58 -0300 From: Alvaro Herrera To: collin.peters@gmail.com Cc: pgsql-bugs@postgresql.org Subject: Re: BUG #12276: Using old name of a renamed or dropped column in a sub-query does not throw error Message-ID: <20141218215458.GR1768@alvh.no-ip.org> References: <20141218213959.1903.81488@wrigleys.postgresql.org> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20141218213959.1903.81488@wrigleys.postgresql.org> User-Agent: Mutt/1.5.23 (2014-03-12) X-Server-Quench: 80946bd0-8700-11e4-9f74-002590a135d3 X-AuthReport-Spam: If SPAM / abuse - report it at: http://www.authsmtp.com/abuse X-AuthRoute: OCdxZQATClZcSBoa BzkeAQdJTRslYBtL RB4bawxAL0wMSABN M15eIxoJcUtFFRZ1 VjUUWVRVVE1zWGlw bwBUaEtcakxQXAJ0 UUlBXFNSFBptCRse BlBdIGAONEchIn5z YEdrWz5YVE1yO059 S0pSRzkGeG9naGAC UUENcx5dJgROYx9F aFV2VCIMYmBTZTQC El17DBoMEg5qYA5o bUlGdAhIHhhZVgMn RhYNVTIrEQUDTiA+ ZxsoYldUBksXO0A/ PRMmQxoUKRgKEgBS V0pKBDJcITtJRixj BEtBQERbCSBQWzYU DholOVdOBSAaRipC A1QNRgsVDDkt X-Authentic-SMTP: 61633235383639.1024:706 X-AuthFastPath: 0 (Was 255) X-AuthSMTP-Origin: 186.37.118.100/587 X-AuthVirus-Status: No virus detected - but ensure you scan with your own anti-virus system. X-Pg-Spam-Score: -2.6 (--) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-bugs Precedence: bulk Sender: pgsql-bugs-owner@postgresql.org collin.peters@gmail.com wrote: > Basically if you rename a column, and then use the original name in a > subquery, that sub-query does not complain that the column no longer exists, > and seems to complete ok. This will cause whatever SELECT or DELETE that is > using the sub-query to continue on its merry way and cause havoc. It's not using the old name of the column --- it's using the name of the OTHER column, that is, the column of the same name in the other table. In essence, your subquery always returns true. > -- select on value of 'bar' and orders for user 1 > -- FAIL - returns all three order lines of 'bar' > SELECT * > FROM order_lines > WHERE value = 'bar' > AND order_id IN ( > -- THIS SHOULD FAIL!! THIS COLUMN NAME DOES NOT EXIST ANYMORE > SELECT order_id > FROM users > WHERE user_id = 1 > ); > > -- same delete as above, except value of 'bar' > DELETE > FROM order_lines > WHERE value = 'bar' > AND order_id IN ( > -- THIS SHOULD FAIL!! THIS COLUMN NAME DOES NOT EXIST ANYMORE > SELECT order_id > FROM users > WHERE user_id = 1 > ); -- Álvaro Herrera http://www.2ndQuadrant.com/ PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services -- Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs