Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1U7GZj-0003iT-GS for pgsql-bugs@arkaria.postgresql.org; Mon, 18 Feb 2013 02:35:27 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.72) (envelope-from ) id 1U7GZi-0005mF-RA for pgsql-bugs@arkaria.postgresql.org; Mon, 18 Feb 2013 02:35:26 +0000 Received: from makus.postgresql.org ([2001:4800:7903:4::125]) by malur.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1U79gb-0000RE-Ow for pgsql-bugs@postgresql.org; Sun, 17 Feb 2013 19:14:05 +0000 Received: from mahout.postgresql.org ([2001:4800:7903:4::123]) by makus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1U79gZ-0005k9-Uh for pgsql-bugs@postgresql.org; Sun, 17 Feb 2013 19:14:05 +0000 Received: from [204.145.124.246] (helo=wrigleys.postgresql.org) by mahout.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1U79gX-0000uf-0G for pgsql-bugs@postgresql.org; Sun, 17 Feb 2013 19:14:02 +0000 Received: from www-data by wrigleys.postgresql.org with local (Exim 4.72) (envelope-from ) id 1U79gW-0003fN-8b for pgsql-bugs@postgresql.org; Sun, 17 Feb 2013 19:14:00 +0000 Date: Sun, 17 Feb 2013 19:14:00 +0000 Message-Id: Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Subject: BUG #7888: Small issue on wiki page Round time To: pgsql-bugs@postgresql.org From: spm@spamik.cz X-Pg-Spam-Score: -2.5 (--) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-bugs Precedence: bulk Sender: pgsql-bugs-owner@postgresql.org The following bug has been logged on the website: Bug reference: 7888 Logged by: Jan Krajdl Email address: spm@spamik.cz PostgreSQL version: Unsupported/Unknown Operating system: all Description:=20=20=20=20=20=20=20=20 Hi, I have found small issue on this wiki page: http://wiki.postgresql.org/wiki/Round_time There is mistake in "alternative approach" function - select '1970-01-01'::timestamptz results in timestamp '1970-01-01 00:00:00' with local timezone. But function is using it as a start of epoch which was same time but in timezone GMT. If you use this function and you have postgres server in non GMT timezone, rounded results are in GMT timezone but they have timezone information about local timezone. I'm quite noob with postgres but I tried to fix it and it looks that this code: CREATE FUNCTION date_round(base_date timestamptz, round_interval INTERVAL) RETURNS timestamptz AS $BODY$ SELECT TIMESTAMP WITH TIME ZONE 'epoch' + (EXTRACT(epoch FROM $1)::INTEGER + EXTRACT(epoch FROM $2)::INTEGER / 2) / EXTRACT(epoch FROM $2)::INTEGER * EXTRACT(epoch FROM $2)::INTEGER * INTERVAL '1 second'; $BODY$ LANGUAGE SQL STABLE; is doing it better - returned time looks correct. So if you want you can update this page. Regards, --=20 Jan Krajdl --=20 Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs