Revision 5849
Added by Aaron Marcuse-Kubitza about 12 years ago
vegbien.sql | ||
---|---|---|
556 | 556 |
|
557 | 557 |
|
558 | 558 |
-- |
559 |
-- Name: sync_aggregated_analytical_db_to_view(); Type: FUNCTION; Schema: public; Owner: - |
|
560 |
-- |
|
561 |
|
|
562 |
CREATE FUNCTION sync_aggregated_analytical_db_to_view() RETURNS void |
|
563 |
LANGUAGE sql |
|
564 |
AS $$ |
|
565 |
DROP TABLE IF EXISTS aggregated_analytical_db; |
|
566 |
CREATE TABLE aggregated_analytical_db AS SELECT * FROM aggregated_analytical_db_view; |
|
567 |
$$; |
|
568 |
|
|
569 |
|
|
570 |
-- |
|
559 | 571 |
-- Name: sync_analytical_db_to_view(); Type: FUNCTION; Schema: public; Owner: - |
560 | 572 |
-- |
561 | 573 |
|
... | ... | |
955 | 967 |
|
956 | 968 |
|
957 | 969 |
-- |
970 |
-- Name: aggregated_analytical_db; Type: TABLE; Schema: public; Owner: -; Tablespace: |
|
971 |
-- |
|
972 |
|
|
973 |
CREATE TABLE aggregated_analytical_db ( |
|
974 |
"institutionCode" text, |
|
975 |
country text, |
|
976 |
"stateProvince" text, |
|
977 |
county text, |
|
978 |
"decimalLatitude" double precision, |
|
979 |
"decimalLongitude" double precision, |
|
980 |
"plotName" text, |
|
981 |
"elevationInMeters" double precision, |
|
982 |
"plotArea_ha" double precision, |
|
983 |
"samplingProtocol" text, |
|
984 |
"dateCollected" date, |
|
985 |
family text, |
|
986 |
genus text, |
|
987 |
"speciesBinomial" text, |
|
988 |
"scientificName" text, |
|
989 |
"scientificNameAuthorship" text, |
|
990 |
"scientificNameWithMorphospecies" text, |
|
991 |
"individualCount" bigint, |
|
992 |
"individualCount_1_to_2_5cm" bigint, |
|
993 |
"individualCount_2_5_to_10cm" bigint, |
|
994 |
"individualCount_10cm_or_more" bigint |
|
995 |
); |
|
996 |
|
|
997 |
|
|
998 |
-- |
|
999 |
-- Name: analytical_db; Type: TABLE; Schema: public; Owner: -; Tablespace: |
|
1000 |
-- |
|
1001 |
|
|
1002 |
CREATE TABLE analytical_db ( |
|
1003 |
"institutionCode" text, |
|
1004 |
country text, |
|
1005 |
"stateProvince" text, |
|
1006 |
county text, |
|
1007 |
"decimalLatitude" double precision, |
|
1008 |
"decimalLongitude" double precision, |
|
1009 |
"plotName" text, |
|
1010 |
"elevationInMeters" double precision, |
|
1011 |
"plotArea_ha" double precision, |
|
1012 |
"samplingProtocol" text, |
|
1013 |
"dateCollected" date, |
|
1014 |
family text, |
|
1015 |
genus text, |
|
1016 |
"speciesBinomial" text, |
|
1017 |
"scientificName" text, |
|
1018 |
"scientificNameAuthorship" text, |
|
1019 |
"scientificNameWithMorphospecies" text, |
|
1020 |
"identifiedBy" text, |
|
1021 |
"growthForm" growthform, |
|
1022 |
cultivated boolean, |
|
1023 |
"cultivatedBasis" text, |
|
1024 |
"coverPercent" double precision, |
|
1025 |
"diameterBreastHeight_cm" double precision, |
|
1026 |
height_m double precision, |
|
1027 |
tag text, |
|
1028 |
"organismX_m" double precision, |
|
1029 |
"organismY_m" double precision, |
|
1030 |
"recordedBy" text, |
|
1031 |
"recordNumber" text |
|
1032 |
); |
|
1033 |
|
|
1034 |
|
|
1035 |
-- |
|
1036 |
-- Name: aggregated_analytical_db_view; Type: VIEW; Schema: public; Owner: - |
|
1037 |
-- |
|
1038 |
|
|
1039 |
CREATE VIEW aggregated_analytical_db_view AS |
|
1040 |
SELECT analytical_db."institutionCode", analytical_db.country, analytical_db."stateProvince", analytical_db.county, analytical_db."decimalLatitude", analytical_db."decimalLongitude", analytical_db."plotName", analytical_db."elevationInMeters", analytical_db."plotArea_ha", analytical_db."samplingProtocol", analytical_db."dateCollected", analytical_db.family, analytical_db.genus, analytical_db."speciesBinomial", analytical_db."scientificName", analytical_db."scientificNameAuthorship", analytical_db."scientificNameWithMorphospecies", count(analytical_db."diameterBreastHeight_cm") AS "individualCount", count(((analytical_db."diameterBreastHeight_cm" >= _cm_to_m((1)::double precision)) AND (analytical_db."diameterBreastHeight_cm" < _cm_to_m((2.5)::double precision)))) AS "individualCount_1_to_2_5cm", count(((analytical_db."diameterBreastHeight_cm" >= _cm_to_m((2.5)::double precision)) AND (analytical_db."diameterBreastHeight_cm" < _cm_to_m((10)::double precision)))) AS "individualCount_2_5_to_10cm", count((analytical_db."diameterBreastHeight_cm" >= _cm_to_m((10)::double precision))) AS "individualCount_10cm_or_more" FROM analytical_db WHERE (analytical_db."diameterBreastHeight_cm" IS NOT NULL) GROUP BY analytical_db."institutionCode", analytical_db.country, analytical_db."stateProvince", analytical_db.county, analytical_db."decimalLatitude", analytical_db."decimalLongitude", analytical_db."plotName", analytical_db."elevationInMeters", analytical_db."plotArea_ha", analytical_db."samplingProtocol", analytical_db."dateCollected", analytical_db.family, analytical_db.genus, analytical_db."speciesBinomial", analytical_db."scientificName", analytical_db."scientificNameAuthorship", analytical_db."scientificNameWithMorphospecies"; |
|
1041 |
|
|
1042 |
|
|
1043 |
-- |
|
958 | 1044 |
-- Name: aggregateoccurrence; Type: TABLE; Schema: public; Owner: -; Tablespace: |
959 | 1045 |
-- |
960 | 1046 |
|
... | ... | |
1021 | 1107 |
|
1022 | 1108 |
|
1023 | 1109 |
-- |
1024 |
-- Name: analytical_db; Type: TABLE; Schema: public; Owner: -; Tablespace: |
|
1025 |
-- |
|
1026 |
|
|
1027 |
CREATE TABLE analytical_db ( |
|
1028 |
"institutionCode" text, |
|
1029 |
country text, |
|
1030 |
"stateProvince" text, |
|
1031 |
county text, |
|
1032 |
"decimalLatitude" double precision, |
|
1033 |
"decimalLongitude" double precision, |
|
1034 |
"plotName" text, |
|
1035 |
"elevationInMeters" double precision, |
|
1036 |
"plotArea_ha" double precision, |
|
1037 |
"samplingProtocol" text, |
|
1038 |
"dateCollected" date, |
|
1039 |
family text, |
|
1040 |
genus text, |
|
1041 |
"speciesBinomial" text, |
|
1042 |
"scientificName" text, |
|
1043 |
"scientificNameAuthorship" text, |
|
1044 |
"scientificNameWithMorphospecies" text, |
|
1045 |
"identifiedBy" text, |
|
1046 |
"growthForm" growthform, |
|
1047 |
cultivated boolean, |
|
1048 |
"cultivatedBasis" text, |
|
1049 |
"coverPercent" double precision, |
|
1050 |
"diameterBreastHeight_cm" double precision, |
|
1051 |
height_m double precision, |
|
1052 |
tag text, |
|
1053 |
"organismX_m" double precision, |
|
1054 |
"organismY_m" double precision, |
|
1055 |
"recordedBy" text, |
|
1056 |
"recordNumber" text |
|
1057 |
); |
|
1058 |
|
|
1059 |
|
|
1060 |
-- |
|
1061 | 1110 |
-- Name: location; Type: TABLE; Schema: public; Owner: -; Tablespace: |
1062 | 1111 |
-- |
1063 | 1112 |
|
Also available in: Unified diff
schemas/vegbien.sql: Added aggregated_analytical_db_view and materialized table aggregated_analytical_db (synced using sync_aggregated_analytical_db_to_view())