Re: How to delete the not DISTINCT ON entries - Mailing list pgsql-sql

From Jean-Luc Lachance
Subject Re: How to delete the not DISTINCT ON entries
Date
Msg-id 40D055B6.5020301@sympatico.ca
Whole thread Raw
In response to Re: How to delete the not DISTINCT ON entries  (Achilleus Mantzios <achill@matrix.gatewaynet.com>)
List pgsql-sql
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
>>
> 
> 



pgsql-sql by date:

Previous
From: Achilleus Mantzios
Date:
Subject: Re: How to delete the not DISTINCT ON entries
Next
From: "Phil Endecott"
Date:
Subject: Inheritance, plpgsql inserting, and revisions