Add new expression type 'xser' to represent series expressions,
[working/Evergreen.git] / Open-ILS / src / sql / Pg / 008.schema.query.sql
index dccb1a6..1a91d66 100644 (file)
@@ -138,6 +138,7 @@ CREATE TABLE query.expression (
                                        'xnull',   -- null
                                                                        'xnum',    -- number
                                                                        'xop',     -- operator
+                                                                       'xser',    -- series
                                                                        'xstr',    -- string
                                                'xsubq'    -- subquery
                                                                ) ),
@@ -1085,6 +1086,61 @@ CREATE OR REPLACE RULE query_expr_xop_delete_rule AS
     DO INSTEAD
     DELETE FROM query.expression WHERE id = OLD.id;
 
+-- Create updatable view for series expressions,
+-- i.e. series of expressions separated by operators
+
+CREATE OR REPLACE VIEW query.expr_xser AS
+    SELECT
+               id,
+               parenthesize,
+               parent_expr,
+               seq_no,
+               operator,
+               negate
+    FROM
+        query.expression
+    WHERE
+        type = 'xser';
+
+CREATE OR REPLACE RULE query_expr_xser_insert_rule AS
+    ON INSERT TO query.expr_xser
+    DO INSTEAD
+    INSERT INTO query.expression (
+               id,
+               type,
+               parenthesize,
+               parent_expr,
+               seq_no,
+               operator,
+               negate
+    ) VALUES (
+        COALESCE(NEW.id, NEXTVAL('query.expression_id_seq'::REGCLASS)),
+        'xser',
+        COALESCE(NEW.parenthesize, FALSE),
+        NEW.parent_expr,
+        COALESCE(NEW.seq_no, 1),
+               NEW.operator,
+               NEW.negate
+    );
+
+CREATE OR REPLACE RULE query_expr_xser_update_rule AS
+    ON UPDATE TO query.expr_xser
+    DO INSTEAD
+    UPDATE query.expression SET
+        id = NEW.id,
+        parenthesize = NEW.parenthesize,
+        parent_expr = NEW.parent_expr,
+        seq_no = NEW.seq_no,
+               operator = NEW.operator,
+               negate = NEW.negate
+    WHERE
+        id = OLD.id;
+
+CREATE OR REPLACE RULE query_expr_xser_delete_rule AS
+    ON DELETE TO query.expr_xser
+    DO INSTEAD
+    DELETE FROM query.expression WHERE id = OLD.id;
+
 -- Create updatable view for string literal expressions
 
 CREATE OR REPLACE VIEW query.expr_xstr AS