Project

General

Profile

« Previous | Next » 

Revision 8321

schemas/util.sql: Added force_update_view()

View differences:

schemas/util.sql
689 689

  
690 690

  
691 691
--
692
-- Name: force_update_view(text, text); Type: FUNCTION; Schema: util; Owner: -
693
--
694

  
695
CREATE FUNCTION force_update_view(view_ text, query text) RETURNS void
696
    LANGUAGE plpgsql STRICT
697
    AS $_$
698
DECLARE
699
	mk_view text = $$CREATE OR REPLACE VIEW $$||view_||$$ AS
700
$$||query;
701
BEGIN
702
	EXECUTE mk_view;
703
EXCEPTION
704
WHEN invalid_table_definition THEN
705
	IF SQLERRM = 'cannot drop columns from view' THEN
706
		EXECUTE $$DROP VIEW $$||view_||$$ CASCADE$$;
707
		EXECUTE mk_view;
708
	ELSE RAISE USING ERRCODE = SQLSTATE, MESSAGE = SQLERRM;
709
	END IF;
710
END;
711
$_$;
712

  
713

  
714
--
715
-- Name: FUNCTION force_update_view(view_ text, query text); Type: COMMENT; Schema: util; Owner: -
716
--
717

  
718
COMMENT ON FUNCTION force_update_view(view_ text, query text) IS 'idempotent';
719

  
720

  
721
--
692 722
-- Name: has_prefix(text, text); Type: FUNCTION; Schema: util; Owner: -
693 723
--
694 724

  

Also available in: Unified diff