Changeset: f98ef5387f4b for MonetDB URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=f98ef5387f4b Modified Files: sql/server/rel_select.c sql/test/subquery/Tests/subquery.sql sql/test/subquery/Tests/subquery.stable.err sql/test/subquery/Tests/subquery.stable.out Branch: Nov2019 Log Message:
If the order by column is not in the projection range, throw a proper error message diffs (65 lines): diff --git a/sql/server/rel_select.c b/sql/server/rel_select.c --- a/sql/server/rel_select.c +++ b/sql/server/rel_select.c @@ -4891,7 +4891,7 @@ rel_order_by(sql_query *query, sql_rel * e = exps_get_exp(rel->exps, nr); if (!e) - return NULL; + return sql_error(sql, 02, SQLSTATE(42000) "SELECT: the order by column number (%d) is not in the number of projections range (%d)", nr, list_length(rel->exps)); e = exp_ref(sql->sa, e); /* do not cache this query */ if (e) diff --git a/sql/test/subquery/Tests/subquery.sql b/sql/test/subquery/Tests/subquery.sql --- a/sql/test/subquery/Tests/subquery.sql +++ b/sql/test/subquery/Tests/subquery.sql @@ -95,6 +95,12 @@ SELECT (VALUES(1),(2)); --error, cardina SELECT (VALUES(1,2,3)); --error, subquery must return only one column +SELECT i FROM integers ORDER BY (SELECT 1); + +SELECT i FROM integers ORDER BY (SELECT 2); --error, the query outputs 1 column, so not possible to order by the second projection + +SELECT i FROM integers ORDER BY (SELECT -1); --error, no in the order by range + drop TABLE integers; -- varchar tests diff --git a/sql/test/subquery/Tests/subquery.stable.err b/sql/test/subquery/Tests/subquery.stable.err --- a/sql/test/subquery/Tests/subquery.stable.err +++ b/sql/test/subquery/Tests/subquery.stable.err @@ -82,6 +82,14 @@ MAPI = (monetdb) /var/tmp/mtest-269215/ QUERY = SELECT (VALUES(1,2,3)); --error, subquery must return only one column ERROR = !SELECT: subquery must return only one column CODE = 42000 +MAPI = (monetdb) /var/tmp/mtest-650620/.s.monetdb.34611 +QUERY = SELECT i FROM integers ORDER BY (SELECT 2); --error, the query outputs 1 column, so not possible to order by the second projection +ERROR = !SELECT: the order by column number (2) is not in the number of projections range (1) +CODE = 42000 +MAPI = (monetdb) /var/tmp/mtest-659896/.s.monetdb.34655 +QUERY = SELECT i FROM integers ORDER BY (SELECT -1); --error, no in the order by range +ERROR = !SELECT: the order by column number (-1) is not in the number of projections range (1) +CODE = 42000 # 17:27:37 > # 17:27:37 > "Done." diff --git a/sql/test/subquery/Tests/subquery.stable.out b/sql/test/subquery/Tests/subquery.stable.out --- a/sql/test/subquery/Tests/subquery.stable.out +++ b/sql/test/subquery/Tests/subquery.stable.out @@ -307,6 +307,15 @@ stdout of test 'subquery` in directory ' % tinyint # type % 1 # length [ 1 ] +#SELECT i FROM integers ORDER BY (SELECT 1); +% sys.integers # table_name +% i # name +% int # type +% 1 # length +[ NULL ] +[ 1 ] +[ 2 ] +[ 3 ] #drop TABLE integers; #CREATE TABLE strings(v VARCHAR(128)); #INSERT INTO strings VALUES ('hello'), ('world'), (NULL); _______________________________________________ checkin-list mailing list checkin-list@monetdb.org https://www.monetdb.org/mailman/listinfo/checkin-list