1 -- Instead of representing a subfield as a distinct expression type in its
2 -- own right, express it as a variant of the xfunc type -- i.e. a function
3 -- call with a column name. In consequence:
5 -- 1. Eliminate the query.expr_xfld view;
7 -- 2. Expand the query.expr_xfunc view to include column_name;
9 -- 3. Eliminate 'xfld' as a valid value for expression.type.
11 -- Theoretically, the latter change could create a problem if you already
12 -- have xfld rows in your expression table. You would have to delete them,
13 -- and represent the corresponding expressions by other means. In practice
14 -- this is exceedingly unlikely, since subfields were never even
15 -- supported until earlier today.
17 -- We start by dropping two views; the first for good, and the second so that
18 -- we can replace it. We drop them outside the transaction so that the
19 -- script won't fail if the views don't exist yet.
21 DROP VIEW query.expr_xfld;
23 DROP VIEW query.expr_xfunc;
27 INSERT INTO config.upgrade_log (version) VALUES ('0322'); -- Scott McKellar
29 -- Eliminate 'xfld' as an expression type
31 ALTER TABLE query.expression
32 DROP CONSTRAINT expression_type;
34 ALTER TABLE query.expression
35 ADD CONSTRAINT expression_type CHECK ( type in (
37 'xbind', -- bind variable
54 -- Create updatable view for function call expressions
56 CREATE OR REPLACE VIEW query.expr_xfunc AS
70 CREATE OR REPLACE RULE query_expr_xfunc_insert_rule AS
71 ON INSERT TO query.expr_xfunc
73 INSERT INTO query.expression (
83 COALESCE(NEW.id, NEXTVAL('query.expression_id_seq'::REGCLASS)),
85 COALESCE(NEW.parenthesize, FALSE),
87 COALESCE(NEW.seq_no, 1),
90 COALESCE(NEW.negate, false)
93 CREATE OR REPLACE RULE query_expr_xfunc_update_rule AS
94 ON UPDATE TO query.expr_xfunc
96 UPDATE query.expression SET
98 parenthesize = NEW.parenthesize,
99 parent_expr = NEW.parent_expr,
101 column_name = NEW.column_name,
102 function_id = NEW.function_id,
107 CREATE OR REPLACE RULE query_expr_xfunc_delete_rule AS
108 ON DELETE TO query.expr_xfunc
110 DELETE FROM query.expression WHERE id = OLD.id;