pg.ddx.io  pgsql-performance@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Jean-Luc Lachance <jllachan@nsd.ca>
To: Greg Spiegelberg <gspiegelberg@cranel.com>
Cc: PgSQL Performance ML <pgsql-performance@postgresql.org>
Subject: Re: Compare rows
Date: Wed, 08 Oct 2003 15:47:24 -0400
Message-ID: <3F8469CC.7379F8D7@nsd.ca> (raw)
References: <3F841A28.8060504@cranel.com>
	<200310080901.45093.josh@agliodbs.com>
	<3F843AFD.3020700@cranel.com>
	<3F843F73.6030302@joeconway.com>
	<3F8459FA.1030008@cranel.com>

Here is what i think you can use:

One master table with out duplicates and one anciliary table with
duplicate for the day.
Insert the result of the select from the anciliary table into the master
table, truncate the anciliary table.


select distinct on ( {all the fields except day}) * from table order by
{all the fields except day}, day;

As in:

select distinct on ( OS, Patch) * from table order by OS, Patch, Day;

JLL

BTW, PG developper, since the distinct on list MUST be included in the
order by clause why not make it implicitly part of the order by clause?



Greg Spiegelberg wrote:
> 
> Joe Conway wrote:
> > Greg Spiegelberg wrote:
> >
> >> The reason for my initial question was this.  We save changes only.
> >> In other words, if system S has row T1 for day D1 and if on day D2
> >> we have another row T1 (excluding our time column) we don't want
> >> to save it.
> >
> >
> > It still isn't entirely clear to me what you are trying to do, but
> > perhaps some sort of calculated checksum or hash would work to determine
> > if the data has changed?
> 
> Best example I have is this.
> 
> You're running Solaris 5.8 with patch 108528-X and you're collecting
> that data daily.  Would you want option 1 or 2 below?
> 
> Option 1 - Store it all
>   Day  |      OS     |   Patch
> ------+-------------+-----------
> Oct 1 | Solaris 5.8 | 108528-12
> Oct 2 | Solaris 5.8 | 108528-12
> Oct 3 | Solaris 5.8 | 108528-13
> Oct 4 | Solaris 5.8 | 108528-13
> Oct 5 | Solaris 5.8 | 108528-13
> and so on...
> 
> To find what you're running:
> select * from table order by day desc limit 1;
> 
> To find when it last changed however takes a join.
> 
> Option 2 - Store only changes
>   Day  |      OS     |   Patch
> ------+-------------+-----------
> Oct 1 | Solaris 5.8 | 108528-12
> Oct 3 | Solaris 5.8 | 108528-13
> 
> To find what you're running:
> select * from table order by day desc limit 1;
> 
> To find when it last changed:
> select * from table order by day desc limit 1 offset 1;
> 
> I selected Option 2 because I'm dealing with mounds of complicated and
> varying data formats and didn't want to have to write complex queries
> for everything.
> 
> Greg
> 
> --
> Greg Spiegelberg
>   Sr. Product Development Engineer
>   Cranel, Incorporated.
>   Phone: 614.318.4314
>   Fax:   614.431.8388
>   Email: gspiegelberg@Cranel.com
> Cranel. Technology. Integrity. Focus.
> 
> ---------------------------(end of broadcast)---------------------------
> TIP 5: Have you checked our extensive FAQ?
> 
>                http://www.postgresql.org/docs/faqs/FAQ.html



view thread (25+ messages)  latest in thread

Message-ID: <3F8469CC.7379F8D7@nsd.ca>
Permalink:  ../3F8469CC.7379F8D7@nsd.ca/
Also on:    postgresql.org/message-id/3F8469CC.7379F8D7@nsd.ca

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-performance@postgresql.org
  Cc: jllachan@nsd.ca, gspiegelberg@cranel.com
  Subject: Re: Compare rows
  In-Reply-To: <3F8469CC.7379F8D7@nsd.ca>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

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