Return-Path: Delivered-To: apmail-db-derby-user-archive@www.apache.org Received: (qmail 50354 invoked from network); 4 Feb 2009 18:44:50 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 4 Feb 2009 18:44:50 -0000 Received: (qmail 80846 invoked by uid 500); 4 Feb 2009 18:44:50 -0000 Delivered-To: apmail-db-derby-user-archive@db.apache.org Received: (qmail 80453 invoked by uid 500); 4 Feb 2009 18:44:49 -0000 Mailing-List: contact derby-user-help@db.apache.org; run by ezmlm Precedence: bulk list-help: list-unsubscribe: List-Post: List-Id: Reply-To: "Derby Discussion" Delivered-To: mailing list derby-user@db.apache.org Received: (qmail 80444 invoked by uid 99); 4 Feb 2009 18:44:49 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 04 Feb 2009 10:44:49 -0800 X-ASF-Spam-Status: No, hits=-4.0 required=10.0 tests=RCVD_IN_DNSWL_MED,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (nike.apache.org: local policy) Received: from [192.18.43.132] (HELO sca-es-mail-1.sun.com) (192.18.43.132) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 04 Feb 2009 18:44:39 +0000 Received: from fe-sfbay-10.sun.com ([192.18.43.129]) by sca-es-mail-1.sun.com (8.13.7+Sun/8.12.9) with ESMTP id n14Ii5EI017730 for ; Wed, 4 Feb 2009 10:44:17 -0800 (PST) MIME-version: 1.0 Content-transfer-encoding: 7BIT Content-type: text/plain; format=flowed; charset=ISO-8859-1 Received: from conversion-daemon.fe-sfbay-10.sun.com by fe-sfbay-10.sun.com (Sun Java(tm) System Messaging Server 7.0-3.01 64bit (built Dec 23 2008)) id <0KEK00I000BPXS00@fe-sfbay-10.sun.com> for derby-user@db.apache.org; Wed, 04 Feb 2009 10:44:05 -0800 (PST) Received: from richard-hillegas-computer.local ([unknown] [129.150.16.231]) by fe-sfbay-10.sun.com (Sun Java(tm) System Messaging Server 7.0-3.01 64bit (built Dec 23 2008)) with ESMTPSA id <0KEK00IR31D7XOB0@fe-sfbay-10.sun.com> for derby-user@db.apache.org; Wed, 04 Feb 2009 10:43:55 -0800 (PST) Date: Wed, 04 Feb 2009 10:43:54 -0800 From: Rick Hillegas Subject: Re: Derby/Oracle - single SQL query? In-reply-to: <032D6760-74DE-4AB7-B033-11E16CCB9473@iotabits.com> Sender: Richard.Hillegas@Sun.COM To: Derby Discussion Message-id: <4989E1EA.3090508@sun.com> References: <032D6760-74DE-4AB7-B033-11E16CCB9473@iotabits.com> User-Agent: Thunderbird 2.0.0.19 (Macintosh/20081209) X-Virus-Checked: Checked by ClamAV on apache.org Kent Spaulding wrote: > Hi again, > > Thanks to the list, I'm able to use the same code for inserts for both > Oracle and Derby drivers. > > Now I have a SQL question, one of my queries has where clauses > (actually, all of them).. > > This works in Derby, not Oracle: > > and cast(d.insertion_date as date) >= '2009-01-01' > and cast(d.insertion_date as date) <= '2009-02-28' > > Derby is smart enough to treat the literal as a DATE. > > This works in Oracle, not Derby: > > and cast(d.insertion_date as date) >= to_date('2009-01-01', > 'YYYY-MM-DD') > and cast(d.insertion_date as date) <= to_date('2009-02-28', > 'YYYY-MM-DD') > > Have to use a function to convert the literal, AFAIK. > > Is there some query format that will for both? > If no, can I add a to_date function to Derby? Hi Kent, You can add your own user-defined to_date function, but you can't add a system function. The big difference, from the point of your syntax, is that a user defined function has to live in the current schema. In contrast, a system function is global across the entire database. Details on how to create a user-defined function can be found in the Reference Guide: http://db.apache.org/derby/docs/dev/ref/ref-single.html#crefsqlj95081 Hope this helps, -Rick > > Thanks in advance, > --Kent