Issue Details (XML | Word | Printable)

Key: DERBY-264
Type: Sub-task Sub-task
Status: Closed Closed
Resolution: Fixed
Priority: Minor Minor
Assignee: Laura Stewart
Reporter: Satheesh Bandaram
Votes: 0
Watchers: 0
Operations

If you were logged in you would be able to see more operations.
Derby
DERBY-134

This enhancement to allow expressions in ORDER BY clause will require documentation changes.

Created: 07/May/05 04:49 AM   Updated: 01/Mar/07 05:46 PM
Return to search
Component/s: Documentation
Affects Version/s: 10.1.1.0, 10.2.1.6
Fix Version/s: 10.3.1.4

Time Tracking:
Not Specified

File Attachments:
  Size
Zip Archive Licensed for inclusion in ASF works derby264-html2.zip 2007-02-21 11:48 PM Laura Stewart 11 kB
File Licensed for inclusion in ASF works derby264_1.diff 2007-02-20 01:34 AM Laura Stewart 11 kB
File Licensed for inclusion in ASF works derby264_2.diff 2007-02-21 11:48 PM Laura Stewart 31 kB
File Licensed for inclusion in ASF works derby264_3.diff 2007-02-27 09:06 PM Laura Stewart 31 kB
Zip Archive Licensed for inclusion in ASF works derby264_html3.zip 2007-02-27 09:06 PM Laura Stewart 11 kB
HTML File Licensed for inclusion in ASF works rrefsqlj13658.html 2007-02-20 01:34 AM Laura Stewart 6 kB
HTML File Licensed for inclusion in ASF works rrefsqlj19433.html 2007-02-20 01:34 AM Laura Stewart 18 kB

Urgency: Low
Resolution Date: 01/Mar/07 12:56 AM


 Description  « Hide
I can help if needed for documenting this enhancement.

 All   Comments   Work Log   Change History   Subversion Commits      Sort Order: Ascending order - Click to sort in descending order
Andrew McIntyre added a comment - 30/Jun/05 06:01 AM
Moving to 10.2 as it appears no one is currently working on this.

Rick Hillegas added a comment - 19/Sep/06 03:42 PM
Moving to 10.2.2.0.

Laura Stewart added a comment - 14/Nov/06 07:52 PM
Can someone please explain what needs to be documented?
I cannot find the thread that is mentioned in Derby134 and there isn't any explanation of what was changed.

Rick Hillegas added a comment - 06/Dec/06 05:37 PM
Move to 10.2.3.0.

Øystein Grøvlen added a comment - 25/Jan/07 10:13 AM
Laura Stewart writes:
> Can someone please explain what needs to be documented?
> I cannot find the thread that is mentioned in Derby134 and there isn't any explanation of what was changed.

I am not sure if it is of much help, but the thread being referred to can be found at:
http://thread.gmane.org/gmane.comp.apache.db.derby.devel/1897

Øystein Grøvlen added a comment - 25/Jan/07 10:57 AM
I think this is what needs to be documented:

     Pre 10.1, the 'ORDER BY' clause of a select statement could only
     contain column references, by name or number. E.g,

         SELECT i FROM t ORDER BY i;
         SELECT i FROM t ORDER BY 1;

     Now, expressions are also allowed in the ORDER BY clause. E.g.,
         
         SELECT i, j FROM t ORDER BY i+j;
         SELECT i, j FROM t ORDER BY f(i);

The documentation for the ORDER BY clause (http://db.apache.org/derby/docs/dev/ref/rrefsqlj13658.html) needs to be updated to reflect this change.

Andrew McIntyre added a comment - 25/Jan/07 08:36 PM
Unsetting Fix Version for unassigned issues.

Laura Stewart added a comment - 16/Feb/07 07:54 PM
Need more information to update the ORDER BY clause topic - http://db.apache.org/derby/docs/dev/ref/

I glanced through the thread that Oystein pointed me to, but did not
find what I need.

1. The type of expressions that are allowed. My impression is that they are the Boolean expressions (as opposed to TableExpressions or SelectExpressions)?

2. I need to understand how the Syntax for ORDER BY should appear. Should it just be "Expressions" added immediately after ColumnPosition (in both places in the Syntax? Are there limitations as to the types of expressions allowed? Boolean, concatenation?

3. Description of the expressions allowed (will appear below the syntax) This will depend on what type of expressions are allowed, but one thing that the other parameters mention is if the column needss to be in the select list.

4. Whatever type of expressions are allowed, that topic in the Derby Ref Guide needs to be updated too. Are there any limitations for ORDER BY? For example, the Boolean expressions topic mentions that there are limitations with check constraints.

Thanks!

Laura Stewart added a comment - 19/Feb/07 06:58 PM
Posted a separate request on derby-dev with the questions I needed help with.

Yip Ng responded with:

Yip Ng <yipng168@gmail.com> to derby-dev

On 2/16/07, Laura Stewart <scotsmatrix@gmail.com> wrote:

> 1. The type of expressions that are allowed. My impression is that
> they are the Boolean expressions (as opposed to TableExpressions or
> SelectExpressions)?


ORDER BY expression is not limited to boolean expression only. It can contain
common value expression such as numeric, string, datetime, etc. It can also
have row value expression such as a scalar subquery, case expression, etc.



> 2. I need to understand how the Syntax for ORDER BY should appear.
> Should it just be "Expressions" added immediately after ColumnPosition
> (in both places in the Syntax? Or should it be specific type of
> expression (TableExpression, SelectExpression, Boolean Expression).
> Are there limitations as to the types of expressions allowed? Boolean,
> concatenation?


Perhaps the name sort-key expression would be more appropriate?
Adding it after Column Position is fine.


> 3. Description of the expressions allowed (will appear below the
> syntax) This will depend on what type of expressions are allowed, but
> one thing that the other parameters mention is if the column needs to
> be in the select list. I need help describing the expressions
> parameter.


> 4. Whatever type of expressions are allowed, that topic in the Derby
> Ref Guide needs to be updated too. Are there any limitations for ORDER
> BY? For example, the Boolean expressions topic mentions that there are
> limitations with check constraints.
>


Yes, there are restrictions. If SELECT DISTINCT is specified or the
SELECT statement contains a GROUP BY clause, the ORDER BY columns need
to appear in the SELECT list.

I think there is a bug in Derby in the DISTINCT with ORDER BY case and
I have filed a jira for this. See DERBY-2351 for further details.

Hope this helps.

Regards,

Yip Ng
 

Laura Stewart added a comment - 20/Feb/07 01:34 AM
Attaching a draft of the patch for reivew.

There are 2 files updated with this patch, the "ORDER BY clause" topic and the "SQL expressions" topic.

There is an open question in the examples in the file rrefsqlj13658.html (ORDER BY clause) which I need help with.

Yip Ng added a comment - 21/Feb/07 12:31 AM
Hi Laura:

I think the following statement can be separated out from the "expression" description and moved it before the Example section since it applies to column-name as well.

"If SELECT DISTINCT is specified or if the SELECT statement contains a GROUP BY clause, the ORDER BY columns must be in the SELECT list."

For the examples, perhaps the following may suffice?


You can sort the result set by a numeric expression, for example:

 SELECT name, salary, bonus FROM employee ORDER BY salary+bonus

where salary and bonus are of decimal type.

You can sort the result set by invoking a function, for example:

  SELECT i, len FROM measures ORDER BY sin(i)








Laura Stewart added a comment - 21/Feb/07 11:48 PM
Attaching a patch and a zip file with the html output.
3 files were updated.

Filename Title Improvements
rrefsqlj13658 ORDER BY clause Added expressions to syntax and examples
rrefsqlj19433 SQL Expressions Added ORDER BY clause, improved index entries, reformatted tables
rrefsqlj23075 Boolean expressions Corrected link

The diff file for rrefsqlj19433 will be hard to read. I really rearranged the tables in this file to make the info easier to find. Please see the html output.

Yip Ng added a comment - 24/Feb/07 07:06 AM
Hi Laura:

I think in the numeric example of the ORDER BY clause ref page, the following statement:

"In this example, the salary and bonus columns must contain DECIMAL data types."

may be better stated with the following:

"In this example, the salary and bonus columns are of DECIMAL data types."





Laura Stewart added a comment - 27/Feb/07 09:06 PM
Attaching the 3rd version of this patch and html files based on the comments from Yip.

Laura Stewart added a comment - 01/Mar/07 12:56 AM
Committed revision 513085.