Update of /cvsroot/monetdb/sql/src/server
In directory sc8-pr-cvs16:/tmp/cvs-serv10154/src/server
Modified Files:
sql_select.mx
Log Message:
allow for order by on columns (not expressions) not in the selection
Index: sql_select.mx
===================================================================
RCS file: /cvsroot/monetdb/sql/src/server/sql_select.mx,v
retrieving revision 1.183
retrieving revision 1.184
diff -u -d -r1.183 -r1.184
--- sql_select.mx 26 Apr 2007 14:35:09 -0000 1.183
+++ sql_select.mx 27 Apr 2007 07:27:31 -0000 1.184
@@ -1347,8 +1347,8 @@
table) so we also do not support it. Unfortunately SQL-3 added new crap,
order by 'expression', where expression should match a result column
expression. We also do not support this (just use as bla and order by bla!).
- SQL-3 supports ordering on columns not in the result table, but again we
- don't.
+ SQL-3 supports ordering on columns not in the result table,
+ we do support that if the column is a direct base column.
*/
static stmt *
orderby_column_ref(mvc *sql, symbol *column_r, stmt *s)
@@ -1399,7 +1399,7 @@
}
static stmt *
-query_orderby(mvc *sql, scope *scp, symbol *orderby, stmt *subset, group *grp,
int by_column_ref)
+query_orderby(mvc *sql, scope *scp, symbol *orderby, stmt *sel, stmt *subset,
group *grp)
{
stmt *cur = NULL;
dnode *o = orderby->data.lval->h;
@@ -1415,9 +1415,15 @@
int direction = order->data.lval->h->next->data.ival;
stmt *sc = NULL;
- if (by_column_ref) {
- sc = orderby_column_ref(sql, col, subset);
- } else {
+ if (sel)
+ sc = orderby_column_ref(sql, col, sel);
+
+ /* fall back to column references, ie those not in
+ the selection result */
+ if (!sc) {
+ /* reset error */
+ sql->errstr[0] = '\0';
+ sql->session->status = 0;
sc = sql_column_ref(sql, scp, col);
if (sc) {
@@ -1475,7 +1481,7 @@
}
/* Order By */
if (window_specification->h->next->data.sym) {
- s = query_orderby(sql, scp,
window_specification->h->next->data.sym, subset, grp, 0 /* cannot use
(selection) column references, as this result is a selection column */ );
+ s = query_orderby(sql, scp,
window_specification->h->next->data.sym, NULL, subset, grp);
}
/* Rank or Aggr function */
if (window_function->token == SQL_RANK) {
@@ -3953,7 +3959,7 @@
}
if (s && subset && sn->orderby) {
- order = query_orderby(sql, scp, sn->orderby, s, NULL, 1);
+ order = query_orderby(sql, scp, sn->orderby, s, subset, NULL);
if (!order) {
sql_select_cleanup(sql, s, subset, grp);
return sql_error(sql, 02, "SELECT: subquery result
missing");
-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
Monetdb-sql-checkins mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/monetdb-sql-checkins