pg.ddx.io  pgsql-admin@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Andrew Perrin <clists@perrin.socsci.unc.edu>
Cc: pgsql-admin@postgresql.org
Subject: Re: URGENT: undoing a mistake
Date: Wed, 30 Oct 2002 22:31:29 -0500
Message-ID: <3467.1036035089@sss.pgh.pa.us> (raw)
In-Reply-To: <Pine.LNX.4.21.0210301550570.690-100000@perrin.socsci.unc.edu>
References: <Pine.LNX.4.21.0210301550570.690-100000@perrin.socsci.unc.edu>

Andrew Perrin <clists@perrin.socsci.unc.edu> writes:
> I just made a mistake that could be quite costly: I did this:
> update writer_survey set partid='W41308' where survid in (select survid
> from participants where partid='W41291' limit 1);
> when I should have done this:
> update writer_survey set partid='W41308' where survid in (select survid
> from writer_survey where partid='W41291' limit 1);

Ooops.

> Is there any way I can undo this, e.g., set partid back to what it was
> before I ran this command? I know I should have done it in a transaction,
> but I didn't.

You're probably out of luck.  Got a recent backup?

(If you were really desperate, and haven't yet vacuumed the table, you
could imagine manually changing the transaction's commit status in
pg_xlog and then clearing any known-committed status bits in the table.
But this is ticklish stuff and there are no tools for it that I know of.)

> More broadly, can someone explain why it worked? There is no survid column
> in participants, so I would have expected it to generate an error on the
> sub-select, not match all rows!

But the sub-select can reference the outer query's variables.  So as
long as "from writer_survey where partid='W41291'" produced at least
one row, the sub-select would return the outer value of survid, and
thus the IN would succeed.

			regards, tom lane



view thread (6+ messages)  latest in thread

Message-ID: <3467.1036035089@sss.pgh.pa.us>
Permalink:  ../3467.1036035089@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/3467.1036035089@sss.pgh.pa.us

 · 

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-admin@postgresql.org
  Cc: tgl@sss.pgh.pa.us, clists@perrin.socsci.unc.edu
  Subject: Re: URGENT: undoing a mistake
  In-Reply-To: <3467.1036035089@sss.pgh.pa.us>
  References: <Pine.LNX.4.21.0210301550570.690-100000@perrin.socsci.unc.edu> <3467.1036035089@sss.pgh.pa.us>

* 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