pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Kevin Grittner <Kevin.Grittner@wicourts.gov>
To: Tom Lane <tgl@sss.pgh.pa.us>
To: Scott Dunbar <scott@xigole.com>
Cc: pgsql-bugs@postgresql.org
Subject: Re: BUG #5898: Nested "in" clauses hide bad column names
Date: Tue, 22 Feb 2011 12:33:23 -0600
Message-ID: <4D63AD13020000250003AE2C@gw.wicourts.gov> (raw)
In-Reply-To: <4D63FB6B.3060804@xigole.com>
References: <201102221726.p1MHQPDh069580@wwwmaster.postgresql.org>
	<3314.1298396703@sss.pgh.pa.us>
	<4D63FB6B.3060804@xigole.com>

Scott Dunbar <scott@xigole.com> wrote:
 
> I guess this makes sense but it does seem strange that I can enter
> garbage in a query but it still runs.
 
It wasn't garbage.
 
> And in my case the output from this (the entire table) was then
> used in a delete statement that toasted the entire table.
 
I can suggest a few ways to protect yourself in such situations.
 
(1)  I generally run any DELETE statement against data I care about
as a SELECT first.  It's generally pretty easy to write it as a
SELECT tbl.* FROM which can be converted to DELETE FROM tbl after
reviewing what matches.
 
(2)  When in doubt, use BEGIN; before running the statement.  You
can review the count, run SELECTs to look at the results, etc.,
before running COMMIT; to make it "stick".
 
(3)  Less convenient, but sometimes useful, is to EXPLAIN your query
before actually running it.  If you do that with your delete, you'll
see the criterion applied to a table other than what you were
expecting, which might alert you to the problem.  The estimated row
count at the top level of the plan might be another red flag.
 
> Allowing bogus SQL just seems "wrong" but I do understand what's
> going on.
 
If you did you wouldn't call a well formed, unambiguous, standard-
conforming statement bogus.  It did exactly what you said; just not
what you meant.  It pays to be a bit paranoid when running ad hoc
DML in case you accidentally don't say what you mean.
 
-Kevin



view thread (5+ messages)  latest in thread

Message-ID: <4D63AD13020000250003AE2C@gw.wicourts.gov>
Permalink:  ../4D63AD13020000250003AE2C@gw.wicourts.gov/
Also on:    postgresql.org/message-id/4D63AD13020000250003AE2C@gw.wicourts.gov

 · 

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: Kevin.Grittner@wicourts.gov, tgl@sss.pgh.pa.us, scott@xigole.com
  Subject: Re: BUG #5898: Nested "in" clauses hide bad column names
  In-Reply-To: <4D63AD13020000250003AE2C@gw.wicourts.gov>
  References: <201102221726.p1MHQPDh069580@wwwmaster.postgresql.org> <3314.1298396703@sss.pgh.pa.us> <4D63FB6B.3060804@xigole.com> <4D63AD13020000250003AE2C@gw.wicourts.gov>

* 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