Re: [GENERAL] From select to delete

2011-10-30 Thread Alexander Farber
I've got another great advice to use DELETE ... USING instead of DELETE ... (SUB-SELECT), so my procedure looks now like this (for archive): create or replace function pref_delete_user(_id varchar, _reason varchar) returns void as $BODY$ begin c

Re: [GENERAL] From select to delete

2011-10-29 Thread Alban Hertroys
On 28 Oct 2011, at 19:02, Alexander Farber wrote: > 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)

Re: [GENERAL] From select to delete

2011-10-29 Thread David Johnston
Original Message- From: pgsql-general-ow...@postgresql.org [mailto:pgsql-general-ow...@postgresql.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

Re: [GENERAL] From select to delete

2011-10-28 Thread Alexander Farber
This seems to work (I'm not sure if ON COMMIT DROP is needed or not - I'm using non-persistent PHP 5.3 script with pgbouncer pool_mode=session and PostgreSQL 8.4.9): create or replace function pref_delete_user(_id varchar, _reason varchar) returns void as $BODY$

Re: [GENERAL] From select to delete

2011-10-28 Thread Alexander Farber
On Fri, Oct 28, 2011 at 7:49 PM, Alban Hertroys wrote: > SELECT INTO in PL/pgSQL isn't the same command as SELECT INTO in SQL. > > Check the documentation for the two ;) > > Alban Hertroys Thanks and I'm not surprised about this news... -- Sent via pgsql-general mailing list (pgsql-general@post

Re: [GENERAL] From select to delete

2011-10-28 Thread Alban Hertroys
On 28 Oct 2011, at 19:40, Alexander Farber wrote: > For now I'm trying to finish my 1st approach > (without "on delete cascade") and the following > strangely fails with > > ERROR: syntax error at "temp" > DETAIL: Expected record variable, row variable, or list of scalar > variables following I

Re: [GENERAL] From select to delete

2011-10-28 Thread Alexander Farber
For now I'm trying to finish my 1st approach (without "on delete cascade") and the following strangely fails with ERROR: syntax error at "temp" DETAIL: Expected record variable, row variable, or list of scalar variables following INTO. CONTEXT: compilation of PL/pgSQL function "pref_delete_user

Re: [GENERAL] From select to delete

2011-10-28 Thread Alexander Farber
Thank you, David - On Fri, Oct 28, 2011 at 7:00 PM, David Johnston 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 yo

Re: [GENERAL] From select to delete

2011-10-28 Thread David Johnston
-Original Message- From: pgsql-general-ow...@postgresql.org [mailto:pgsql-general-ow...@postgresql.org] On Behalf Of Alexander Farber Sent: Friday, October 28, 2011 12:34 PM To: pgsql-general Subject: [GENERAL] From select to delete Hello, Is there maybe an easy way to delete that player

Re: [GENERAL] From select to delete

2011-10-28 Thread Alexander Farber
Nevermind, sorry - I've figured it out myself (for a change) delete from pref_scores where id<>_id and gid in (select gid from pref_scores where id=_id); delete from pref_games where gid in (select gid from pref_scores where

Re: [GENERAL] From select to delete

2011-10-28 Thread Alexander Farber
First half is delete from pref_scores where gid in (select gid from pref_scores where id=_id); but how to clean pref_games? -- Sent via pgsql-general mailing list (pgsql-general@postgresql.org) To make changes to your subscription: http://www.postgresql.org/

[GENERAL] From select to delete

2011-10-28 Thread Alexander Farber
Hello, in PostgreSQL 8.4.9 I'm able to select all games and his partners by a player id: # select * from pref_scores s1 join pref_scores s2 using(gid) join pref_games g using(gid) where s1.id='OK531282114947'; gid | id | money | quit | id | money | quit | rounds |