Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1a8jxW-0000sG-0B for pgsql-jdbc@arkaria.postgresql.org; Tue, 15 Dec 2015 07:23:42 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84) (envelope-from ) id 1a8jxV-0005Cs-BV for pgsql-jdbc@arkaria.postgresql.org; Tue, 15 Dec 2015 07:23:41 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84) (envelope-from ) id 1a8jxU-0005Cg-Py for pgsql-jdbc@postgresql.org; Tue, 15 Dec 2015 07:23:40 +0000 Received: from plane.gmane.org ([80.91.229.3]) by magus.postgresql.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:256) (Exim 4.84) (envelope-from ) id 1a8jxR-0002Zm-0y for pgsql-jdbc@postgresql.org; Tue, 15 Dec 2015 07:23:40 +0000 Received: from list by plane.gmane.org with local (Exim 4.69) (envelope-from ) id 1a8jxO-0004B3-4a for pgsql-jdbc@postgresql.org; Tue, 15 Dec 2015 08:23:34 +0100 Received: from 185.40.248.10 ([185.40.248.10]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Tue, 15 Dec 2015 08:23:34 +0100 Received: from spam_eater by 185.40.248.10 with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Tue, 15 Dec 2015 08:23:34 +0100 X-Injected-Via-Gmane: http://gmane.org/ To: pgsql-jdbc@postgresql.org From: Thomas Kellerer Subject: Re: timestampdiff() implementation Date: Tue, 15 Dec 2015 08:23:26 +0100 Lines: 51 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-Complaints-To: usenet@ger.gmane.org X-Gmane-NNTP-Posting-Host: 185.40.248.10 User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.23) Gecko/20090812 Thunderbird/2.0.0.23 Mnenhy/0.7.6.666 In-Reply-To: X-Pg-Spam-Score: -0.4 (/) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-jdbc Precedence: bulk Sender: pgsql-jdbc-owner@postgresql.org Matthew Bellew schrieb am 15.12.2015 um 03:05: > I recently discovered surprising behavior of the {fn timstampdiff()} > function. I'm seeing that this function seems to extract a portion of > the interval rather than converting it to the requested units. The > documentation makes it obvious that this is the intended > implementation > > 1) It does not interoperate with timestampadd in an arithmetic way > > SELECT {fn timestampadd(SQL_TSI_MINUTE, > 90, > {ts '2000-01-01 1:00:00'} > )} as expr1 > > RETURNS 2000-01-01 02:30 This looks correct to me. The above expressions returns the result of "90 minutes after 01:00:00" which *has* to be 02:30:00 What result would you expect of adding 90 minutes to 01:00:00? Plus: it is the same result as "plain" SQL would return. The following statement: SELECT {fn timestampadd(SQL_TSI_MINUTE,90,{ts '2000-01-01 1:00:00'})} as jdbc_result, timestamp '2000-01-01 01:00:00' + interval '90' minute as sql_result; using a JDBC based SQL client returns: jdbc_result | sql_result ------------------------+------------------------ 2000-01-01 02:30:00.001 | 2000-01-01 02:30:00.001 Both the jTDS and the Microsoft driver for SQL Server also return 2000-01-01 02:30:00.001 for {fn timestampadd(SQL_TSI_MINUTE,90,{ts '2000-01-01 01:00:00'})} So I don't see what timestampadd() does wrong. > I believe the correct translate {fn timestampdiff{SQL_TSI_MINUTE,...)} is something like > > EXTRACT(EPOCH FROM ...)/60; > No, the equivalent of {fn timestampdiff{SQL_TSI_MINUTE,...)} is adding an interval (minutes) to a timestamp as shown above. Thomas -- Sent via pgsql-jdbc mailing list (pgsql-jdbc@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-jdbc