Received: from localhost (postgresql.org [64.49.215.8]) by postgresql.org (Postfix) with ESMTP id 5A245475A1E for ; Wed, 30 Oct 2002 22:31:32 -0500 (EST) Received: from sss.pgh.pa.us (unknown [192.204.191.242]) by postgresql.org (Postfix) with ESMTP id B56AC474E5C for ; Wed, 30 Oct 2002 22:31:31 -0500 (EST) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.12.5/8.12.5) with ESMTP id g9V3VUhR003468; Wed, 30 Oct 2002 22:31:30 -0500 (EST) To: Andrew Perrin Cc: pgsql-admin@postgresql.org Subject: Re: URGENT: undoing a mistake In-reply-to: References: Comments: In-reply-to Andrew Perrin message dated "Wed, 30 Oct 2002 15:53:15 -0500" Date: Wed, 30 Oct 2002 22:31:29 -0500 Message-ID: <3467.1036035089@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: by AMaViS new-20020517 X-Archive-Number: 200210/311 X-Sequence-Number: 6169 Andrew Perrin 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