Revision 8187
Added by Aaron Marcuse-Kubitza over 11 years ago
schemas/util.sql | ||
---|---|---|
723 | 723 |
|
724 | 724 |
|
725 | 725 |
-- |
726 |
-- Name: mk_derived_col(col_ref, text); Type: FUNCTION; Schema: util; Owner: - |
|
727 |
-- |
|
728 |
|
|
729 |
CREATE FUNCTION mk_derived_col(col col_ref, expr text) RETURNS void |
|
730 |
LANGUAGE plpgsql STRICT |
|
731 |
AS $_$ |
|
732 |
DECLARE |
|
733 |
type regtype = util.typeof(expr, col.table_::text::regtype); |
|
734 |
col_name_sql text = quote_ident(col.name); |
|
735 |
BEGIN |
|
736 |
PERFORM util.create_if_not_exists($$ |
|
737 |
ALTER TABLE $$||col.table_||$$ ADD COLUMN $$||col_name_sql||$$ $$||type||$$; |
|
738 |
ALTER TABLE $$||col.table_||$$ ALTER COLUMN $$||col_name_sql||$$ TYPE $$||type||$$ USING |
|
739 |
$$||expr||$$; |
|
740 |
$$); |
|
741 |
END; |
|
742 |
$_$; |
|
743 |
|
|
744 |
|
|
745 |
-- |
|
726 | 746 |
-- Name: mk_map_table(text); Type: FUNCTION; Schema: util; Owner: - |
727 | 747 |
-- |
728 | 748 |
|
Also available in: Unified diff
schemas/util.sql: Added mk_derived_col()