Project

General

Profile

« Previous | Next » 

Revision 12259

schemas/vegbien.sql: added rematerialize_out_view(datasource_schema text, out_view regclass)

View differences:

trunk/schemas/vegbien.my.sql
865 865

  
866 866

  
867 867

  
868

  
869

  
868 870
--
871
-- Name: rematerialize_out_view(varchar(255), regclass); Type: FUNCTION; Schema: public_validations; Owner: -
872
--
873

  
874

  
875

  
876

  
877
--
878
-- Name: FUNCTION rematerialize_out_view(datasource_schema varchar(255), out_view regclass); Type: COMMENT; Schema: public_validations; Owner: -
879
--
880

  
881

  
882

  
883

  
884

  
885

  
886
--
869 887
-- Name: analytical_stem; Type: TABLE; Schema: public; Owner: -; Tablespace: 
870 888
--
871 889

  
trunk/schemas/vegbien.sql
1927 1927
$$;
1928 1928

  
1929 1929

  
1930
SET search_path = public_validations, pg_catalog;
1931

  
1930 1932
--
1933
-- Name: rematerialize_out_view(text, regclass); Type: FUNCTION; Schema: public_validations; Owner: -
1934
--
1935

  
1936
CREATE FUNCTION rematerialize_out_view(datasource_schema text, out_view regclass) RETURNS regclass
1937
    LANGUAGE plpgsql
1938
    AS $$
1939
/* must use LANGUAGE plpgsql because LANGUAGE sql does not support runtime
1940
changes of search_path (schema elements are bound at inline time rather than
1941
runtime) */
1942
DECLARE
1943
	out_table text = '_out_'||util.name(out_view);
1944
BEGIN
1945
	/* datasource_schema must be 1st in the search_path so that queries can use
1946
	it in current_schema, and so that out_table is created in the datasource's
1947
	schema */
1948
	PERFORM set_config('search_path', util.mk_search_path(datasource_schema),
1949
		true);
1950
	
1951
	PERFORM util.rematerialize_view(out_table, out_view);
1952
	
1953
	RETURN out_table;
1954
END;
1955
$$;
1956

  
1957

  
1958
--
1959
-- Name: FUNCTION rematerialize_out_view(datasource_schema text, out_view regclass); Type: COMMENT; Schema: public_validations; Owner: -
1960
--
1961

  
1962
COMMENT ON FUNCTION rematerialize_out_view(datasource_schema text, out_view regclass) IS '
1963
helper function; use rematerialize_out_view(in_view) instead
1964

  
1965
usage:
1966
SELECT public_validations.rematerialize_out_view(''datasource'', ''public_validations._view_name'') AS out_table;
1967

  
1968
idempotent, but repeats action each time
1969
';
1970

  
1971

  
1972
SET search_path = public, pg_catalog;
1973

  
1974
--
1931 1975
-- Name: analytical_stem; Type: TABLE; Schema: public; Owner: -; Tablespace: 
1932 1976
--
1933 1977

  

Also available in: Unified diff