Re: From select to delete

From: "David Johnston" <polobo(at)yahoo(dot)com>
To: "'Alexander Farber'" <alexander(dot)farber(at)gmail(dot)com>
Cc: "'pgsql-general'" <pgsql-general(at)postgresql(dot)org>
Subject: Re: From select to delete
Date: 2011-10-29 14:27:37
Message-ID: 016401cc9646$e891fb20$b9b5f160$@yahoo.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

----Original Message-----
From: pgsql-general-owner(at)postgresql(dot)org
[mailto:pgsql-general-owner(at)postgresql(dot)org] On Behalf Of Alexander Farber
Sent: Friday, October 28, 2011 1:03 PM
Cc: pgsql-general
Subject: Re: [GENERAL] From select to delete

Thank you, David -

On Fri, Oct 28, 2011 at 7:00 PM, David Johnston <polobo(at)yahoo(dot)com> wrote:
> The easiest way is to create FOREIGN KEY relationships between the
> various tables and allow "ON DELETE CASCADE" to do the work.
>
> Otherwise you need to DELETE with an appropriate WHERE clause (and
> sub-selects) or you can use the "USING" clause with the DELETE to add
> additional condition tables.
>
> DELETE FROM t1
> USING (t2 JOIN t3 ON (...)) t_linked
> WHERE t1.something = t_linked.something;
>

I'll try that.

My own 3 commands suggested above fail with

Foreign key violation: 7 ERROR: update or delete on table "pref_games"
violates foreign key constraint "pref_scores_gid_fkey" on table
"pref_scores" DETAIL: Key (gid)=(1998) is still referenced from table
"pref_scores". CONTEXT: SQL statement "delete from pref_games where gid in
(select gid from pref_scores where id= $1 )"

Regards
Alex

------/Original Message --------

Ok. And your question is?

Dave

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Craig Ringer 2011-10-29 16:05:34 Re: PG_DUMP error : unexpected chunk number
Previous Message gouse shaik 2011-10-29 11:17:48