Re: Delete with subquery deleting all records

From: Francisco Reyes <lists(at)stringsutils(dot)com>
To: Alban Hertroys <alban(at)magproductions(dot)nl>
Cc: PostgreSQL general <pgsql-general(at)postgresql(dot)org>
Subject: Re: Delete with subquery deleting all records
Date: 2007-05-25 00:20:42
Message-ID: cone.1180052442.281492.39101.5001@35st.simplicato.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Alban Hertroys writes:

> Why not use EXISTS?
>
> DELETE FROM export_messages WHERE NOT EXISTS (
> SELECT 1
> FROM exports
> WHERE exports.export_id = export_messages.export_id
> )

Didn't think of it. Thanks for the code.

> I suppose you run those queries in a transaction block, right?

Correct.
Also I do a backup before doing the deletions.

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Andrew Sullivan 2007-05-25 00:39:11 Re: why postgresql over other RDBMS
Previous Message Rodrigo De León 2007-05-25 00:05:20 Re: Limiting number of rows returned at a time in select query