Return-Path: Delivered-To: apmail-db-derby-dev-archive@www.apache.org Received: (qmail 3236 invoked from network); 15 Apr 2010 17:52:13 -0000 Received: from unknown (HELO mail.apache.org) (140.211.11.3) by 140.211.11.9 with SMTP; 15 Apr 2010 17:52:13 -0000 Received: (qmail 32797 invoked by uid 500); 15 Apr 2010 17:52:13 -0000 Delivered-To: apmail-db-derby-dev-archive@db.apache.org Received: (qmail 32720 invoked by uid 500); 15 Apr 2010 17:52:13 -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 32711 invoked by uid 99); 15 Apr 2010 17:52:13 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 15 Apr 2010 17:52:13 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.22] (HELO thor.apache.org) (140.211.11.22) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 15 Apr 2010 17:52:11 +0000 Received: from thor (localhost [127.0.0.1]) by thor.apache.org (8.13.8+Sun/8.13.8) with ESMTP id o3FHpnfi024132 for ; Thu, 15 Apr 2010 13:51:49 -0400 (EDT) Message-ID: <3501547.145951271353909127.JavaMail.jira@thor> Date: Thu, 15 Apr 2010 13:51:49 -0400 (EDT) From: "C.S. Nirmal J. Fernando (JIRA)" To: derby-dev@db.apache.org Subject: [jira] Commented: (DERBY-4406) Wrong order when using ORDER BY on non-deterministic function In-Reply-To: <1093343113.1255361491709.JavaMail.jira@brutus> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-JIRA-FingerPrint: 30527f35849b9dde25b450d4833f0394 X-Virus-Checked: Checked by ClamAV on apache.org [ https://issues.apache.org/jira/browse/DERBY-4406?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12857436#action_12857436 ] C.S. Nirmal J. Fernando commented on DERBY-4406: ------------------------------------------------ Hi, I found that, 1) "select random() from t order by random()" == "select random() as r from t order by random()" is considered as a valid query in Postgre SQL. 2) "SELECT i*RANDOM() AS R FROM T ORDER BY i*RANDOM()": In Postgre SQL they're ordering this by R. 3)"SELECT i, i*RANDOM() AS R FROM T ORDER BY i*RANDOM() ": In Postgre SQL they're ordering the result set by i*RANDOM() that means by R. > Wrong order when using ORDER BY on non-deterministic function > ------------------------------------------------------------- > > Key: DERBY-4406 > URL: https://issues.apache.org/jira/browse/DERBY-4406 > Project: Derby > Issue Type: Bug > Components: SQL > Affects Versions: 10.5.3.0, 10.6.0.0 > Reporter: Knut Anders Hatlen > Assignee: C.S. Nirmal J. Fernando > > If I read the SQL standard correctly, a statement such as "select random() as r from t order by random()" should be treated as "select random() as r from t order by r". Derby does however generate a second, hidden random() column by which the rows are ordered. > ij> create table t(x int); > 0 rows inserted/updated/deleted > ij> insert into t values 1,2,3,4,5; > 5 rows inserted/updated/deleted > ij> -- wrong result, not ordered by r > ij> select random() as r from t order by random(); > R > ---------------------- > 0.1285512465366495 > 0.5116860880915798 > 0.21060042130229073 > 0.2506706923680875 > 0.6378857329935494 > 5 rows selected > ij> -- correct result, ordered by r > ij> select random() as r from t order by r; > R > ---------------------- > 0.0749025910679918 > 0.07694931688380491 > 0.1724114605785414 > 0.2268758969382877 > 0.31900450349277965 > 5 rows selected -- This message is automatically generated by JIRA. - If you think it was sent incorrectly contact one of the administrators: https://issues.apache.org/jira/secure/Administrators.jspa - For more information on JIRA, see: http://www.atlassian.com/software/jira