Project

General

Profile

« Previous | Next » 

Revision 7172

schemas/vegbien.sql: sync_analytical_stem_to_view(): Changed to PL/pgSQL function to allow adding PL/pgSQL commands

View differences:

schemas/vegbien.sql
943 943
--
944 944

  
945 945
CREATE FUNCTION sync_analytical_stem_to_view() RETURNS void
946
    LANGUAGE sql
946
    LANGUAGE plpgsql
947 947
    AS $$
948
DROP TABLE IF EXISTS analytical_stem;
949
CREATE TABLE analytical_stem AS SELECT * FROM analytical_stem_view LIMIT 0;
950

  
951
GRANT SELECT ON TABLE analytical_stem TO bien_read;
952
GRANT SELECT ON TABLE analytical_stem_view TO bien_read;
953

  
954
ALTER TABLE analytical_stem ADD FOREIGN KEY (datasource) REFERENCES source (shortname) ON UPDATE CASCADE ON DELETE CASCADE;
955

  
956
ALTER TABLE analytical_stem ALTER COLUMN "datasource" SET NOT NULL;
957
ALTER TABLE analytical_stem ALTER COLUMN "locationID" SET NOT NULL;
958

  
959
CREATE INDEX ON analytical_stem ("datasource", "occurrenceID" );
960
CREATE INDEX ON analytical_stem ("datasource", "institutionCode", "collectionCode", "catalogNumber" );
961
CREATE INDEX ON analytical_stem ("datasource", "projectID", "locationID", "dateCollected" );
948
BEGIN
949
    DROP TABLE IF EXISTS analytical_stem;
950
    CREATE TABLE analytical_stem AS SELECT * FROM analytical_stem_view LIMIT 0;
951
    
952
    GRANT SELECT ON TABLE analytical_stem TO bien_read;
953
    GRANT SELECT ON TABLE analytical_stem_view TO bien_read;
954
    
955
    ALTER TABLE analytical_stem ADD FOREIGN KEY (datasource) REFERENCES source (shortname) ON UPDATE CASCADE ON DELETE CASCADE;
956
    
957
    ALTER TABLE analytical_stem ALTER COLUMN "datasource" SET NOT NULL;
958
    ALTER TABLE analytical_stem ALTER COLUMN "locationID" SET NOT NULL;
959
    
960
    CREATE INDEX ON analytical_stem ("datasource", "occurrenceID");
961
    CREATE INDEX ON analytical_stem ("datasource", "institutionCode", "collectionCode", "catalogNumber");
962
    CREATE INDEX ON analytical_stem ("datasource", "projectID", "locationID", "dateCollected");
963
END;
962 964
$$;
963 965

  
964 966

  

Also available in: Unified diff