X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.130]) by svr1.postgresql.org (Postfix) with ESMTP id 73E7CD1B4E3 for ; Wed, 8 Oct 2003 19:36:24 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (neptune.hub.org [64.117.224.130]) (amavisd-new, port 10024) with ESMTP id 31478-04 for ; Wed, 8 Oct 2003 16:35:36 -0300 (ADT) Received: from beamish.nsd.ca (beamish.nsd.ca [205.150.156.194]) by svr1.postgresql.org (Postfix) with ESMTP id C343FD1B4EA for ; Wed, 8 Oct 2003 16:35:30 -0300 (ADT) Received: (from smap@localhost) by beamish.nsd.ca (8.9.3/8.9.3) id PAA16717; Wed, 8 Oct 2003 15:35:24 -0400 X-Authentication-Warning: beamish.nsd.ca: smap set sender to using -f Received: from reddog.nsd.ca(192.168.101.30) by beamish.nsd.ca via smap (V2.1/2.1+anti-relay+anti-spam) id xma016713; Wed, 8 Oct 03 15:35:23 -0400 Received: from nsd.ca (jllachan-linux.nsd.ca [192.168.101.148]) by reddog.nsd.ca (8.8.7/8.8.7) with ESMTP id PAA30120; Wed, 8 Oct 2003 15:21:11 -0400 Message-ID: <3F8469CC.7379F8D7@nsd.ca> Date: Wed, 08 Oct 2003 15:47:24 -0400 From: Jean-Luc Lachance X-Mailer: Mozilla 4.8 [en] (X11; U; Linux 2.4.18-24.7.x i686) X-Accept-Language: en MIME-Version: 1.0 To: Greg Spiegelberg Cc: PgSQL Performance ML Subject: Re: Compare rows References: <3F841A28.8060504@cranel.com> <200310080901.45093.josh@agliodbs.com> <3F843AFD.3020700@cranel.com> <3F843F73.6030302@joeconway.com> <3F8459FA.1030008@cranel.com> Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at postgresql.org X-Archive-Number: 200310/243 X-Sequence-Number: 3991 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