Changeset: c5c0ed0ebe89 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/c5c0ed0ebe89
Modified Files:
        sql/server/rel_select.c
        sql/server/rel_updates.c
Branch: returning
Log Message:

prevent aggregate function and subqueries in returning clause


diffs (35 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
@@ -3473,7 +3473,7 @@ static sql_exp *
                        return sql_error(sql, 02, SQLSTATE(42000) "%s: 
aggregate functions not allowed in WHERE clause", toUpperCopy(uaname, aname));
                } else if (is_sql_update_set(f) || is_sql_psm(f)) {
                        char *uaname = SA_NEW_ARRAY(sql->ta, char, 
strlen(aname) + 1);
-                       return sql_error(sql, 02, SQLSTATE(42000) "%s: 
aggregate functions not allowed in SET, WHILE, IF, ELSE, CASE, WHEN, RETURN, 
ANALYZE clauses (use subquery)", toUpperCopy(uaname, aname));
+                       return sql_error(sql, 02, SQLSTATE(42000) "%s: 
aggregate functions not allowed in SET, WHILE, IF, ELSE, CASE, WHEN, RETURN, 
ANALYZE, RETURNING clauses (use subquery)", toUpperCopy(uaname, aname));
                } else if (is_sql_aggr(f)) {
                        char *uaname = SA_NEW_ARRAY(sql->ta, char, 
strlen(aname) + 1);
                        return sql_error(sql, 02, SQLSTATE(42000) "%s: 
aggregate functions cannot be nested", toUpperCopy(uaname, aname));
diff --git a/sql/server/rel_updates.c b/sql/server/rel_updates.c
--- a/sql/server/rel_updates.c
+++ b/sql/server/rel_updates.c
@@ -1317,7 +1317,9 @@ delete_table(sql_query *query, dlist *qn
                        list *pexps = sa_list(sql->sa);
                        for (dnode *n = opt_returning->h; n; n = n->next) {
                                sql_rel* inner = r->l;
-                               sql_exp *ce = rel_column_exp(query, &inner, 
n->data.sym, sql_sel);
+                               sql_exp *ce = rel_column_exp(query, &inner, 
n->data.sym, sql_sel | sql_no_subquery | sql_update_set);
+                               if (ce == NULL)
+                                       return sql_error(sql, 02, 
SQLSTATE(42000) "aggregate functions and subqueries are not allowed in 
RETURNING clause");
                                pexps = append(pexps, ce);
                        }
                        r->attr = pexps;
@@ -2208,7 +2210,7 @@ rel_updates(sql_query *query, symbol *s)
                dlist *l = s->data.lval;
 
                ret = delete_table(query, l->h->data.lval, 
l->h->next->data.sval, l->h->next->next->data.sym, 
l->h->next->next->next->data.lval);
-               if (!ret->attr) sql->type = Q_UPDATE;
+               if (ret && !ret->attr) sql->type = Q_UPDATE;
        }
                break;
        case SQL_TRUNCATE:
_______________________________________________
checkin-list mailing list -- checkin-list@monetdb.org
To unsubscribe send an email to checkin-list-le...@monetdb.org

Reply via email to