Revision 14205
Added by Aaron Marcuse-Kubitza over 10 years ago
trunk/schemas/util.sql | ||
---|---|---|
1754 | 1754 |
|
1755 | 1755 |
|
1756 | 1756 |
-- |
1757 |
-- Name: derived_col_update(derived_col_def); Type: FUNCTION; Schema: util; Owner: - |
|
1758 |
-- |
|
1759 |
|
|
1760 |
CREATE FUNCTION derived_col_update(def derived_col_def) RETURNS void |
|
1761 |
LANGUAGE sql |
|
1762 |
AS $$ |
|
1763 |
SELECT util.col_add(def); |
|
1764 |
|
|
1765 |
-- if table has data, initially disabled because not yet populated |
|
1766 |
SELECT util.check_constraint((def.col, util.derived_col_constraint_expr(def)), |
|
1767 |
enabled := NOT util.table_has_data((def).col.table_)); |
|
1768 |
|
|
1769 |
-- create the trigger |
|
1770 |
SELECT util.derived_cols_sync((def).col.table_); |
|
1771 |
$$; |
|
1772 |
|
|
1773 |
|
|
1774 |
-- |
|
1775 |
-- Name: FUNCTION derived_col_update(def derived_col_def); Type: COMMENT; Schema: util; Owner: - |
|
1776 |
-- |
|
1777 |
|
|
1778 |
COMMENT ON FUNCTION derived_col_update(def derived_col_def) IS ' |
|
1779 |
**IMPORTANT**: unless the table is empty, remember to run |
|
1780 |
util.derived_cols_populate() after this |
|
1781 |
|
|
1782 |
usage: |
|
1783 |
SELECT util.derived_col_update(((''table'', ''col1''), $$col1_expr$$)); |
|
1784 |
SELECT util.derived_col_update(((''table'', ''col2''), $$col2_expr$$)); |
|
1785 |
-- if table has data: |
|
1786 |
SELECT util.derived_cols_populate(''table''); |
|
1787 |
|
|
1788 |
idempotent |
|
1789 |
'; |
|
1790 |
|
|
1791 |
|
|
1792 |
-- |
|
1757 | 1793 |
-- Name: derived_cols(regclass, regclass); Type: FUNCTION; Schema: util; Owner: - |
1758 | 1794 |
-- |
1759 | 1795 |
|
Also available in: Unified diff
schemas/util.sql: added derived_col_update()