pg.ddx.io pgsql-sql@postgresql.org mailing list archive
help / color / mirror / Atom feedHow to delete the not DISTINCT ON entries
3+ messages / 3 participants
[nested] [flat]
* How to delete the not DISTINCT ON entries
@ 2004-06-16 11:52 Christoph Haller <ch@rodos.fzk.de>
2004-06-16 12:18 ` Re: How to delete the not DISTINCT ON entries Achilleus Mantzios <achill@matrix.gatewaynet.com>
0 siblings, 1 reply; 3+ messages in thread
From: Christoph Haller @ 2004-06-16 11:52 UTC (permalink / raw)
To: pgsql-sql
Referring to the DISTINCT ON example
SELECT DISTINCT ON (location) location, time, report
FROM weatherReports
ORDER BY location, time DESC;
How would I delete those entries skipped by the DISTINCT ON expression?
TIA
Regards, Christoph
^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: How to delete the not DISTINCT ON entries
2004-06-16 11:52 How to delete the not DISTINCT ON entries Christoph Haller <ch@rodos.fzk.de>
@ 2004-06-16 12:18 ` Achilleus Mantzios <achill@matrix.gatewaynet.com>
2004-06-16 14:14 ` Re: How to delete the not DISTINCT ON entries Jean-Luc Lachance <jllachan@sympatico.ca>
0 siblings, 1 reply; 3+ messages in thread
From: Achilleus Mantzios @ 2004-06-16 12:18 UTC (permalink / raw)
To: Christoph Haller <ch@rodos.fzk.de>; +Cc: pgsql-sql
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
>
--
-Achilleus
^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: How to delete the not DISTINCT ON entries
2004-06-16 11:52 How to delete the not DISTINCT ON entries Christoph Haller <ch@rodos.fzk.de>
2004-06-16 12:18 ` Re: How to delete the not DISTINCT ON entries Achilleus Mantzios <achill@matrix.gatewaynet.com>
@ 2004-06-16 14:14 ` Jean-Luc Lachance <jllachan@sympatico.ca>
0 siblings, 0 replies; 3+ messages in thread
From: Jean-Luc Lachance @ 2004-06-16 14:14 UTC (permalink / raw)
To: Achilleus Mantzios <achill@matrix.gatewaynet.com>; +Cc: Christoph Haller <ch@rodos.fzk.de>; 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
>>
>
>
^ permalink raw reply [nested|flat] 3+ messages in thread
end of thread, other threads:[~2004-06-16 14:14 UTC | newest]
Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2004-06-16 11:52 How to delete the not DISTINCT ON entries Christoph Haller <ch@rodos.fzk.de>
2004-06-16 12:18 ` Achilleus Mantzios <achill@matrix.gatewaynet.com>
2004-06-16 14:14 ` Jean-Luc Lachance <jllachan@sympatico.ca>
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox