Return-Path: X-Original-To: apmail-db-derby-dev-archive@www.apache.org Delivered-To: apmail-db-derby-dev-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 49247D76B for ; Fri, 17 Aug 2012 16:25:39 +0000 (UTC) Received: (qmail 16078 invoked by uid 500); 17 Aug 2012 16:25:39 -0000 Delivered-To: apmail-db-derby-dev-archive@db.apache.org Received: (qmail 16031 invoked by uid 500); 17 Aug 2012 16:25:39 -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: Delivered-To: mailing list derby-dev@db.apache.org Received: (qmail 15827 invoked by uid 99); 17 Aug 2012 16:25:38 -0000 Received: from arcas.apache.org (HELO arcas) (140.211.11.28) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 17 Aug 2012 16:25:38 +0000 Received: from arcas.apache.org (localhost [127.0.0.1]) by arcas (Postfix) with ESMTP id 5995B2C5BE8 for ; Fri, 17 Aug 2012 16:25:38 +0000 (UTC) Date: Sat, 18 Aug 2012 03:25:38 +1100 (NCT) From: "Knut Anders Hatlen (JIRA)" To: derby-dev@db.apache.org Message-ID: <283225435.23970.1345220738367.JavaMail.jiratomcat@arcas> In-Reply-To: <262328554.1900.1344868478312.JavaMail.jiratomcat@arcas> Subject: [jira] [Commented] (DERBY-5901) You can declare user-defined functions which shadow builtin functions by the same name. MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-JIRA-FingerPrint: 30527f35849b9dde25b450d4833f0394 [ https://issues.apache.org/jira/browse/DERBY-5901?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13436835#comment-13436835 ] Knut Anders Hatlen commented on DERBY-5901: ------------------------------------------- I think I'd prefer option (1). The compatibility issues sound more manageable with that option (a failure is easier to detect than silently changing the results). Also, option (2) opens for the possibility that you can create a function which is shadowed by a built-in function, and if you don't know that there is a built-in with the same name, you may unknowingly call the wrong method in your SQL queries. > You can declare user-defined functions which shadow builtin functions by the same name. > --------------------------------------------------------------------------------------- > > Key: DERBY-5901 > URL: https://issues.apache.org/jira/browse/DERBY-5901 > Project: Derby > Issue Type: Bug > Components: SQL > Affects Versions: 10.10.0.0 > Reporter: Rick Hillegas > > You can override a Derby builtin function by creating a function with the same name. This can give rise to wrong results. > Consider the following user code: > public class FakeSin > { > public static Double sin( Double input ) { return new Double( 3.0 ); } > } > Now run the following script: > connect 'jdbc:derby:memory:db;create=true'; > values sin( 0.5 ); > create function sin( a double ) returns double language java parameter style java no sql external name 'FakeSin.sin'; > values sin( 0.5 ); > values sin( 0.5 ); > Note the following: > 1) The first invocation of sin() returns the expected result. > 2) You are allowed to create a user-defined function named "sin" which can shadow the builtin function. > 3) The second invocation of sin() returns the result of running the builtin function. This is because the second invocation is character-for-character identical to the first, so Derby just uses the previously prepared statement. > 4) But the third invocation of sin() returns the result of running the user-defined function. Note that the third invocation has an extra space in it, which causes Derby to compile it from scratch, picking up the user-defined function instead of the builtin one. -- This message is automatically generated by JIRA. If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa For more information on JIRA, see: http://www.atlassian.com/software/jira