Created
May 21, 2012 16:44
-
-
Save robheittman/2763207 to your computer and use it in GitHub Desktop.
Static tables for Red List publish
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
vacuum analyze; | |
drop table if exists st_countryoccurrencesubfield_countryoccurrencelookup; | |
create table st_countryoccurrencesubfield_countryoccurrencelookup as select * from vw_published.vw_countryoccurrencesubfield_countryoccurrencelookup ; | |
drop table if exists st_countryoccurrencesubfield_presence; | |
create table st_countryoccurrencesubfield_presence as select * from vw_published.vw_countryoccurrencesubfield_presence; | |
drop table if exists st_countryoccurrencesubfield_origin; | |
create table st_countryoccurrencesubfield_origin as select * from vw_published.vw_countryoccurrencesubfield_origin; | |
DROP TABLE IF EXISTS st_countryoccurrence; | |
CREATE TABLE st_countryoccurrence AS | |
SELECT country.taxonid, country.assessmentid, country.value, country.recordid, record."CODE" as code, record."DESCRIPTION" as country, pres."LABEL" as presence, origin."LABEL" as origin | |
FROM st_countryoccurrencesubfield_countryoccurrencelookup country | |
JOIN lookups."COUNTRYOCCURRENCELOOKUP" record ON record."ID" = country.value | |
LEFT JOIN st_countryoccurrencesubfield_presence c_pres ON country.recordid = c_pres.recordid | |
LEFT JOIN lookups."COUNTRYOCCURRENCE_PRESENCELOOKUP" pres ON pres."ID" = c_pres.value | |
LEFT JOIN st_countryoccurrencesubfield_origin c_origin ON country.recordid = c_origin.recordid | |
LEFT JOIN lookups."COUNTRYOCCURRENCE_ORIGINLOOKUP" origin ON origin."ID" = c_origin.value; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment