Re: [HACKERS] Table aliases in delete statements?

From: Keith Parks <emkxp01(at)mtcc(dot)demon(dot)co(dot)uk>
To: emkxp01(at)mtcc(dot)demon(dot)co(dot)uk, pgman(at)candle(dot)pha(dot)pa(dot)us
Cc: hackers(at)postgresql(dot)org
Subject: Re: [HACKERS] Table aliases in delete statements?
Date: 1999-12-08 00:48:12
Message-ID: 199912080048.AAA10593@mtcc.demon.co.uk
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers


>Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us>

>
>> emkxp01=> delete from deltest s1 where s1.respdate not in ( select
>> min(s2.respdate) from deltest s2 where s1.sessionid = s2.sessionid);
>> ERROR: parser: parse error at or near "s1"
>> emkxp01=>
>
>Don't use s1. Just refer to native deltest in the subquery. That
>should reference the outer table.

That doesn't seem to work as 3 rows are deleted and not just the
two duplicates.

emkxp01=> delete from deltest where respdate not in ( select min(s2.respdate)
from deltest s2 where sessionid = s2.sessionid);
DELETE 3
emkxp01=> select * from deltest;
sessionid | respdate
-----------+------------------------------
1 | Tue 07 Dec 22:32:01 1999 GMT
(1 row)

emkxp01=>

Keith.

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Keith Parks 1999-12-08 00:52:03 Re: [HACKERS] Table aliases in delete statements?
Previous Message Jan Wieck 1999-12-08 00:31:17 Re: [HACKERS] Raising funds for PostgreSQL