Re: Compare rows - Mailing list pgsql-performance
From | Jean-Luc Lachance |
---|---|
Subject | Re: Compare rows |
Date | |
Msg-id | 3F8469CC.7379F8D7@nsd.ca Whole thread Raw |
In response to | Compare rows (Greg Spiegelberg <gspiegelberg@cranel.com>) |
List | pgsql-performance |
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
pgsql-performance by date: