X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 386FAD1B275 for ; Wed, 16 Jun 2004 11:13:18 -0300 (ADT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 49992-03 for ; Wed, 16 Jun 2004 14:13:18 +0000 (GMT) Received: from simmts5-srv.bellnexxia.net (simmts5.bellnexxia.net [206.47.199.163]) by svr1.postgresql.org (Postfix) with ESMTP id 31150D1B2BD for ; Wed, 16 Jun 2004 11:13:13 -0300 (ADT) Received: from localhost ([67.71.24.121]) by simmts5-srv.bellnexxia.net (InterMail vM.5.01.06.10 201-253-122-130-110-20040306) with ESMTP id <20040616141301.CPDM3387.simmts5-srv.bellnexxia.net@localhost>; Wed, 16 Jun 2004 10:13:01 -0400 Received: from sympatico.ca ([192.168.250.6]) by (8.11.6/8.11.6) with ESMTP id i5GEDFg27291; Wed, 16 Jun 2004 10:13:15 -0400 Message-ID: <40D055B6.5020301@sympatico.ca> Date: Wed, 16 Jun 2004 10:14:14 -0400 From: Jean-Luc Lachance User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.4) Gecko/20030624 Netscape/7.1 (ax) X-Accept-Language: en, en-us, en-gb, fr, fr-ca MIME-Version: 1.0 To: Achilleus Mantzios Cc: Christoph Haller , pgsql-sql@postgresql.org Subject: Re: How to delete the not DISTINCT ON entries References: In-Reply-To: Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= X-Spam-Level: X-Archive-Number: 200406/141 X-Sequence-Number: 18086 If you do not have foreign key restrinctions, create a temp table from the select as: CREATE TEMP TABLE tmp AS SELECT DISTINCT ON (location) location, time, report FROM weatherReports ORDER BY location, time DESC; TRUNCATE weatherReports; INSERT INTO weatherReports SELECT * FROM tmp; HTH Achilleus Mantzios wrote: > O kyrios Christoph Haller egrapse stis Jun 16, 2004 : > > >>Referring to the DISTINCT ON example >> >>SELECT DISTINCT ON (location) location, time, report >>FROM weatherReports >>ORDER BY location, time DESC; > > > maybe smth like > > delete from weatherReports where (location,time,report) not in > (SELECT DISTINCT ON (location) location, time, report FROM weatherReports > ORDER BY location, time DESC) > > Note: > Order by is very important, since it affects which rows are deleted. > > >>How would I delete those entries skipped by the DISTINCT ON expression? >> >>TIA >> >>Regards, Christoph >> >> >> >>---------------------------(end of broadcast)--------------------------- >>TIP 6: Have you searched our list archives? >> >> http://archives.postgresql.org >> > >