diff --git a/README.md b/README.md index 17dd493..fb1e715 100644 --- a/README.md +++ b/README.md @@ -223,6 +223,9 @@ DROP TABLE my_table IF EXISTS - File name can also be absolute path. - See `data/q1.sql` for more information +## Delete Data: +- Use a query like `DELETE FROM [WHERE ]` to delete rows from a table that matches the conditions. + ## Built-in functions: - `avg[s]`: average of a column. `avgs(col), avgs(w, col)` is rolling and moving average with window `w` of the column `col`. - `var[s]`, `stddev[s]`: [moving/rolling] **population** variance, standard deviation. diff --git a/reconstruct/ast.py b/reconstruct/ast.py index 14ab94e..8486ae8 100644 --- a/reconstruct/ast.py +++ b/reconstruct/ast.py @@ -937,7 +937,8 @@ class filter(ast_node): def produce(self, node): filter_expr = expr(self, node) self.add(filter_expr.sql) - self.datasource.join_conditions += filter_expr.join_conditions + if self.datasource is not None: + self.datasource.join_conditions += filter_expr.join_conditions class create_table(ast_node): name = 'create_table' @@ -1052,7 +1053,19 @@ class insert(ast_node): self.sql += ', '.join(list_values) - + +class delete_table(ast_node): + name = 'delete' + first_order = name + def init(self, node): + super().init(node) + + def produce(self, node): + tbl = node['delete'] + self.sql = f'DELETE FROM {tbl} ' + if 'where' in node: + self.sql += filter(self, node['where']).sql + class load(ast_node): name="load" first_order = name