pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Alvaro Herrera <alvherre@2ndquadrant.com>
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
Date: Thu, 18 Dec 2014 18:54:58 -0300
Message-ID: <20141218215458.GR1768@alvh.no-ip.org> (raw)
In-Reply-To: <20141218213959.1903.81488@wrigleys.postgresql.org>
References: <20141218213959.1903.81488@wrigleys.postgresql.org>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-bugs>

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



view thread (5+ messages)  latest in thread

Message-ID: <20141218215458.GR1768@alvh.no-ip.org>
Permalink:  ../20141218215458.GR1768@alvh.no-ip.org/
Also on:    postgresql.org/message-id/20141218215458.GR1768@alvh.no-ip.org

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-bugs@postgresql.org
  Cc: alvherre@2ndquadrant.com, collin.peters@gmail.com
  Subject: Re: BUG #12276: Using old name of a renamed or dropped column in a sub-query does not throw error
  In-Reply-To: <20141218215458.GR1768@alvh.no-ip.org>
  References: <20141218213959.1903.81488@wrigleys.postgresql.org> <20141218215458.GR1768@alvh.no-ip.org>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox