Return-Path: Delivered-To: apmail-db-derby-dev-archive@www.apache.org Received: (qmail 62188 invoked from network); 17 May 2005 01:00:20 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 17 May 2005 01:00:20 -0000 Received: (qmail 57410 invoked by uid 500); 16 May 2005 17:41:00 -0000 Delivered-To: apmail-db-derby-dev-archive@db.apache.org Received: (qmail 57320 invoked by uid 500); 16 May 2005 17:40:59 -0000 Mailing-List: contact derby-dev-help@db.apache.org; run by ezmlm Precedence: bulk list-help: list-unsubscribe: List-Post: List-Id: Reply-To: "Derby Development" Delivered-To: mailing list derby-dev@db.apache.org Received: (qmail 57207 invoked by uid 99); 16 May 2005 17:40:57 -0000 X-ASF-Spam-Status: No, hits=0.4 required=10.0 tests=SPF_HELO_FAIL X-Spam-Check-By: apache.org Received-SPF: neutral (hermes.apache.org: local policy) Received: from e33.co.us.ibm.com (HELO e33.co.us.ibm.com) (32.97.110.131) by apache.org (qpsmtpd/0.28) with ESMTP; Mon, 16 May 2005 10:40:56 -0700 Received: from d03relay04.boulder.ibm.com (d03relay04.boulder.ibm.com [9.17.195.106]) by e33.co.us.ibm.com (8.12.10/8.12.9) with ESMTP id j4GHegmD126386 for ; Mon, 16 May 2005 13:40:43 -0400 Received: from d03av02.boulder.ibm.com (d03av02.boulder.ibm.com [9.17.195.168]) by d03relay04.boulder.ibm.com (8.12.10/NCO/VER6.6) with ESMTP id j4GHeQGc235704 for ; Mon, 16 May 2005 11:40:42 -0600 Received: from d03av02.boulder.ibm.com (loopback [127.0.0.1]) by d03av02.boulder.ibm.com (8.12.11/8.13.3) with ESMTP id j4GHePGX015661 for ; Mon, 16 May 2005 11:40:25 -0600 Received: from [127.0.0.1] (sig-9-48-105-197.mts.ibm.com [9.48.105.197]) by d03av02.boulder.ibm.com (8.12.11/8.12.11) with ESMTP id j4GHdwmf014130 for ; Mon, 16 May 2005 11:40:06 -0600 Message-ID: <4288DAE5.9090008@debrunners.com> Date: Mon, 16 May 2005 10:39:49 -0700 From: Daniel John Debrunner User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.3) Gecko/20040910 X-Accept-Language: en-us, en MIME-Version: 1.0 To: Derby Development Subject: Re: [PATCH] Timestamp Arithmetic References: <4284D2C1.3090902@sbcglobal.net> In-Reply-To: <4284D2C1.3090902@sbcglobal.net> X-Enigmail-Version: 0.90.0.0 X-Enigmail-Supports: pgp-inline, pgp-mime Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Virus-Checked: Checked X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N Jack wrote ... A few items in your patch & description gave me pause for thought ... > If a date is used in ts1 or ts2 it is converted to a timestamp by using time 00:00:00. > If a time is used in ts1 or ts2 it is converted to a timestamp by using the current date. a) the lack of symmetry in these statements, current date but not current time b) what did you mean by current time, as there is "SQL current timestamp" and "real time now"? I see you implemented as real time. [SQL has the CURRENT_TIMESTAMP fixed for the lifetime of a statement] c) current date in which timezone? [I see that Derby uses this rule for casting from a TIME to a TIMESTAMP, and the manuals state CURRENT_DATE, which would be fixed for the lifetime of the statement.] a) means that TIMESTAMPADD() can return different values for a given TIME argument value at different times, e.g. TIME + 1 DAY will depend on which day the function is executed. That combined with b) means that within a single query TIMESTAMPADD() can return different values for a given TIME argument value, i.e. if a query's execution spans midnight. That behaviour for a SQL function just seems wrong. Then the naming of the new methods in DateTimeDataValue seemed wrong, I'm a great believer in ensuring such items and method names correctly reflect their purpose. This makes the code more readable. So we have > + DateTimeDataValue timestampAdd( int intervalType, NumberDataValue intervalCount, DateTimeDataValue resultHolder) > + throws StandardException; If I have a expression equivalent to TIME + 1 MIN, then I'm not adding a timestamp, I'm adding one minute to the current value of the DateTimeDataValue object. This is an interface method, declaration of behaviour, not implementation. Similar for > + NumberDataValue timestampDiff( int intervalType, DateTimeDataValue time1, NumberDataValue resultHolder) > + throws StandardException; If I'm diffing two TIME values and returning interval in minutes then no timestamp is involved. It seems a more correct reflection of their names would be intervalAdd and intervalDiff. So all this thinking got me to the key point is I think there are combinations of interval and SQL types that should not be allowed. - Since SQL TIME is not associated with a date then I believe that adding or diffing any date related intervals should not be allowed. - Since SQL DATE is not associated with a time then I believe that adding or diffing any time related intervals should not be allowed. - And diffing TIME against a DATE etc. should not be allowed. [this matches the existing documentation that says different date time types cannot be mixed in an expression] So with JDBC escape functions equivalent to these expressions TIME + 1 DAY // not allowed DATE + 1 MIN // not allowed DATE - TIME // not allowed Of course this leads to either (and similar for DATE) {fn TIMESTAMPADD( interval, count,