pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
Deleting obsolete values
3+ messages / 3 participants
[nested] [flat]

* Deleting obsolete values
@ 1970-01-01 00:00 Haller Christoph <ch@rodos.fzk.de>
  2001-10-19 12:56 ` Re: Deleting obsolete values Pat M <pmeloy@removethispart.home.com>
  0 siblings, 1 reply; 3+ messages in thread

From: Haller Christoph @ 1970-01-01 00:00 UTC (permalink / raw)
  To: pgsql-sql

This may look familiar to you - it was on the list last month. 
Consider the following table 
create table partitur
 (userid text, val integer, ts timestamp DEFAULT NOW() );
Do some inserts 
insert into partitur values('Bart', 1440);
insert into partitur values('Lisa', 1024);
insert into partitur values('Bart', 7616);
insert into partitur values('Lisa', 3760);
insert into partitur values('Bart', 3760);
insert into partitur values('Lisa', 7616);
To retrieve the latest values (meaning the last ones inserted) 
Tom Lane wrote 
>This is what SELECT DISTINCT ON was invented for.  I don't know any
>comparably easy way to do it in standard SQL, but with DISTINCT ON
>it's not hard:
>SELECT DISTINCT ON (userid) userid, val, ts FROM partitur
>ORDER BY userid, ts DESC;

My question now is 
Is there a way to delete all rows the select statement did not 
bring up? 
After that *unknown* delete statement 
select userid, val, ts from partitur ;
should show exactly the same as the SELECT DISTINCT ON (userid) ... 
did before. 

Regards, Christoph 



^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: Deleting obsolete values
  1970-01-01 00:00 Deleting obsolete values Haller Christoph <ch@rodos.fzk.de>
@ 2001-10-19 12:56 ` Pat M <pmeloy@removethispart.home.com>
  0 siblings, 0 replies; 3+ messages in thread

From: Pat M @ 2001-10-19 12:56 UTC (permalink / raw)
  To: pgsql-sql

Delete from partitur where userid NOT IN (SELECT DISTINCT ON (userid)
userid, val, ts FROM partitur)

"Haller Christoph" <ch@rodos.fzk.de> wrote in message
news:200110161445.QAA11833@rodos...
> This may look familiar to you - it was on the list last month.
> Consider the following table
> create table partitur
>  (userid text, val integer, ts timestamp DEFAULT NOW() );
> Do some inserts
> insert into partitur values('Bart', 1440);
> insert into partitur values('Lisa', 1024);
> insert into partitur values('Bart', 7616);
> insert into partitur values('Lisa', 3760);
> insert into partitur values('Bart', 3760);
> insert into partitur values('Lisa', 7616);
> To retrieve the latest values (meaning the last ones inserted)
> Tom Lane wrote
> >This is what SELECT DISTINCT ON was invented for.  I don't know any
> >comparably easy way to do it in standard SQL, but with DISTINCT ON
> >it's not hard:
> >SELECT DISTINCT ON (userid) userid, val, ts FROM partitur
> >ORDER BY userid, ts DESC;
>
> My question now is
> Is there a way to delete all rows the select statement did not
> bring up?
> After that *unknown* delete statement
> select userid, val, ts from partitur ;
> should show exactly the same as the SELECT DISTINCT ON (userid) ...
> did before.
>
> Regards, Christoph
>
> ---------------------------(end of broadcast)---------------------------
> TIP 2: you can get off all lists at once with the unregister command
>     (send "unregister YourEmailAddressHere" to majordomo@postgresql.org)





^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: Deleting obsolete values
@ 2001-10-18 13:28 Henshall, Stuart - WCP <SHenshall@westcountrypublications.co.uk>
  0 siblings, 0 replies; 3+ messages in thread

From: Henshall, Stuart - WCP @ 2001-10-18 13:28 UTC (permalink / raw)
  To: 'Haller Christoph' <ch@rodos.fzk.de>; pgsql-sql

DELETE FROM partitur WHERE EXISTS (SELECT * FROM partitur AS ss_partitur
WHERE ss_partitur.userid=partitur.userid AND ss_partitur.ts>partitur.ts);
Seems like it should seems like it should delete all old values (however I
have not tested it)
- Stuart

> -----Original Message-----
> From:	Haller Christoph [SMTP:ch@rodos.fzk.de]
> Sent:	Tuesday, October 16, 2001 5:45 PM
> To:	pgsql-sql@postgresql.org
> Subject:	Deleting obsolete values
> 
> This may look familiar to you - it was on the list last month. 
> Consider the following table 
> create table partitur
>  (userid text, val integer, ts timestamp DEFAULT NOW() );
> Do some inserts 
> insert into partitur values('Bart', 1440);
> insert into partitur values('Lisa', 1024);
> insert into partitur values('Bart', 7616);
> insert into partitur values('Lisa', 3760);
> insert into partitur values('Bart', 3760);
> insert into partitur values('Lisa', 7616);
> To retrieve the latest values (meaning the last ones inserted) 
> Tom Lane wrote 
> >This is what SELECT DISTINCT ON was invented for.  I don't know any
> >comparably easy way to do it in standard SQL, but with DISTINCT ON
> >it's not hard:
> >SELECT DISTINCT ON (userid) userid, val, ts FROM partitur
> >ORDER BY userid, ts DESC;
> 
> My question now is 
> Is there a way to delete all rows the select statement did not 
> bring up? 
> After that *unknown* delete statement 
> select userid, val, ts from partitur ;
> should show exactly the same as the SELECT DISTINCT ON (userid) ... 
> did before. 
> 
> Regards, Christoph 



^ permalink  raw  reply  [nested|flat] 3+ messages in thread


end of thread, other threads:[~2001-10-19 12:56 UTC | newest]

Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
1970-01-01 00:00 Deleting obsolete values Haller Christoph <ch@rodos.fzk.de>
2001-10-19 12:56 ` Pat M <pmeloy@removethispart.home.com>
2001-10-18 13:28 Re: Deleting obsolete values Henshall, Stuart - WCP <SHenshall@westcountrypublications.co.uk>

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