Issue Details (XML | Word | Printable)

Key: DERBY-3066
Type: Improvement Improvement
Status: Closed Closed
Resolution: Duplicate
Priority: Minor Minor
Assignee: Unassigned
Reporter: Thomas Nielsen
Votes: 0
Watchers: 0
Operations

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

WHERE clause not accepted on derived expression columns

Created: 11/Sep/07 07:52 AM   Updated: 14/Sep/07 06:43 AM
Return to search
Component/s: SQL
Affects Version/s: None
Fix Version/s: None

Time Tracking:
Not Specified

Issue Links:
Duplicate
 
Reference
 

Resolution Date: 14/Sep/07 06:43 AM


 Description  « Hide
A very simple query involving an expression column with a derived name in the WHERE clause fails:

ij> select a+b as s from t where s > 2;
ERROR 42X04: Column 'S' is either not in any table in the FROM list or appears within a join specification and is outside the scope of the join specification or appears in a HAVING clause and is not in the GROUP BY list. If this is a CREATE or ALTER TABLE statement then 'S' is not a column in the target table.

Noticed this while working on DERBY-2998, and AFAIK this is a valid query and a limitation in derby.

There is a workaround for this using a nested select (output from a test table):
ij> select * from (select a+b as s from t) as t(s) where s > 2;
S
-----------
10
10
10

3 rows selected

 All   Comments   Work Log   Change History   Subversion Commits      Sort Order: Ascending order - Click to sort in descending order
Andrew McIntyre added a comment - 11/Sep/07 05:39 PM
Possibly a duplicate of DERBY-84? Certainly related, linking to that issue. See also DERBY-2457 and DERBY-2970.

Bryan Pendleton added a comment - 12/Sep/07 06:22 PM
I agree, this is a duplicate of DERBY-84.

Furthermore, I agree with Jack Klebanoff's comment in DERBY-84 that this is not a bug (https://issues.apache.org/jira/browse/DERBY-84#action_66872).

W.R.T. DERBY-2998, I think that the nested select construction of row_number() restrictions is the form that should be used.

Thomas Nielsen added a comment - 14/Sep/07 06:25 AM
Thanks for catching the duplicate of DERBY-84 Andrew.
We can close this one.

Thomas Nielsen added a comment - 14/Sep/07 06:43 AM
Duplicate of DERBY-84