Received: from maia.hub.org (maia-5.hub.org [200.46.204.29]) by mail.postgresql.org (Postfix) with ESMTP id 57A411337B49 for ; Sat, 26 Feb 2011 17:39:12 -0400 (AST) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.29]) (amavisd-maia, port 10024) with ESMTP id 60662-03 for ; Sat, 26 Feb 2011 21:39:05 +0000 (UTC) X-Greylist: delayed 00:44:07.590108 by SQLgrey-1.7.6 Received: from ka.mail.enyo.de (ka.mail.enyo.de [87.106.162.201]) by mail.postgresql.org (Postfix) with ESMTP id 3B8DC1336B42 for ; Sat, 26 Feb 2011 17:39:04 -0400 (AST) Received: from [172.17.135.4] (helo=deneb.enyo.de) by ka.mail.enyo.de with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) id 1PtRAA-00010p-MY; Sat, 26 Feb 2011 21:54:50 +0100 Received: from fw by deneb.enyo.de with local (Exim 4.72) (envelope-from ) id 1PtRAA-0006F0-EZ; Sat, 26 Feb 2011 21:54:50 +0100 From: Florian Weimer To: "Kevin Grittner" Cc: "Dave Crooke" , "pgsql-performance" Subject: Re: Picking out the most recent row using a time stamp column References: <4D6668CF020000250003AFC9@gw.wicourts.gov> Date: Sat, 26 Feb 2011 21:54:50 +0100 In-Reply-To: <4D6668CF020000250003AFC9@gw.wicourts.gov> (Kevin Grittner's message of "Thu, 24 Feb 2011 14:18:55 -0600") Message-ID: <87r5auwm79.fsf@mid.deneb.enyo.de> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.91 tagged_above=-10 required=5 tests=BAYES_00=-1.9, T_RP_MATCHES_RCVD=-0.01 X-Spam-Level: X-Archive-Number: 201102/504 X-Sequence-Number: 42642 * Kevin Grittner: > Dave Crooke wrote: > >> create table data >> (id_key int, >> time_stamp timestamp without time zone, >> value double precision); >> >> create unique index data_idx on data (id_key, time_stamp); > >> I need to find the most recent value for each distinct value of >> id_key. > > Well, unless you use timestamp WITH time zone, you might not be able > to do that at all. There are very few places where timestamp > WITHOUT time zone actually makes sense. I don't think PostgreSQL keeps track of actual time zone values, just as it doesn't keep track of the character encoding of TEXT columns. Unless suppressed with WITHOUT TIME ZONE, PostgreSQL makes up some time zone on demand. This makes TIMESTAMP WITH TIME ZONE not that useful, and it's often to use TIMESTAMP WITHOUT TIME ZONE with times in UTC.