-- Name: vw_belastingen_gwl_csv_nieuw; Type: VIEW; Schema: public; Owner: -
--

CREATE VIEW vw_belastingen_gwl_csv_nieuw AS
 SELECT vw_grondwaterlichamen.identificatie AS "Grondwaterlichaam.Identificatie",
    vw_grondwaterlichamen.versie,
    gw_pressure_type.description AS "BelastingSoort",
    pressure_category_type.omschrijving AS "BelastingCategorie",
    gwb_pressure.is_significant AS "SignificantJN",
    pressure_relevance_type.omschrijving AS "Urgentie",
    gwb_pressure.remark AS "Opmerking",
    ( SELECT array_to_string(ARRAY( SELECT drivers.naam
                   FROM (domains.drivers
                     JOIN gw_pressure_type_driver ON (((drivers.driver_id = gw_pressure_type_driver.driver_id) AND (gw_pressure_type_driver.gprs_id = gw_pressure_type.gprs_id))))), ','::text) AS array_to_string) AS "Functie",
    ( SELECT array_to_string(ARRAY( SELECT impacts.naam
                   FROM (domains.impacts
                     JOIN gwb_pressure_impact ON (((impacts.impact_id = gwb_pressure_impact.impact_id) AND (gwb_pressure_impact.gwbp_id = gwb_pressure.gwbp_id))))), ','::text) AS array_to_string) AS "Impact"
   FROM vw_grondwaterlichamen,
    gwb_pressure,
    gw_pressure_type,
    pressure_category_type,
    pressure_relevance_type
  WHERE ((vw_grondwaterlichamen.db_id = gwb_pressure.gwb_id) AND (gw_pressure_type.gprs_id = gwb_pressure.gprs_id) AND (pressure_category_type.pcat_id = gw_pressure_type.pressure_category_id) AND (gwb_pressure.prr_id = pressure_relevance_type.prr_id) AND (gw_pressure_type.d_eind IS NULL));


--
-- Name: vw_belastingen_owm; Type: VIEW; Schema: public; Owner: -
--

CREATE VIEW vw_belastingen_owm AS
 SELECT swb_pressure.swbp_id AS "DB_ID",
    vw_waterlichamen.db_id AS "Oppervlaktewaterlichaam_DB_ID",
    vw_waterlichamen.identificatie AS "Oppervlaktewaterlichaam_Identificatie",
    sw_pressure_type.description AS "Type",
    pressure_category_type.omschrijving AS "Categorie",
    swb_pressure.is_significant AS "SignificantJN",
    drivers.naam AS "Functie",
    swb_pressure.effect AS "Effecten",
    swb_pressure.remark AS "Opmerking"
   FROM vw_waterlichamen,
    swb_pressure,
    sw_pressure_type,
    pressure_category_type,
    sw_pressure_type_driver,
    domains.drivers
  WHERE ((vw_waterlichamen.db_id = swb_pressure.swb_id) AND (sw_pressure_type.sprs_id = swb_pressure.sprs_id) AND (pressure_category_type.pcat_id = sw_pressure_type.pressure_category_id) AND (sw_pressure_type.sprs_id = sw_pressure_type_driver.sprs_id) AND (sw_pressure_type_driver.driver_id = drivers.driver_id))
  ORDER BY vw_waterlichamen.identificatie, swb_pressure.sprs_id DESC, pressure_category_type.omschrijving;


--
-- Name: vw_oppervlaktewaterlichamen; Type: VIEW; Schema: public; Owner: -
--

CREATE VIEW vw_oppervlaktewaterlichamen AS
 SELECT DISTINCT ON (vw_waterlichamen.db_id) vw_waterlichamen.db_id,
    vw_waterlichamen.identificatie,
    vw_waterlichamen.waterbeheerder_code,
    vw_waterlichamen.omschrijving,
    vw_waterlichamen.schaal,
    vw_waterlichamen.stroomgebieddistrict,
    surface_water_body.is_artificial AS is_kunstmatig,
    surface_water_body.is_heaviliy_modified AS is_sterk_veranderd,
        CASE
            WHEN (surface_water_body.is_artificial = true) THEN 'Kunstmatig'::text
            WHEN (surface_water_body.is_heaviliy_modified = true) THEN 'Sterk veranderd'::text
            ELSE 'Natuurlijk'::text
        END AS waterlichaam_status,
    surface_water_body.area_value AS oppervlakte_waarde,
    surface_water_body.area_uom_id,
    surface_water_body.length_value AS lengte_waarde,
    surface_water_body.length_uom_id,
    surface_water_body.other_pressure_description,
    surface_water_body.other_impact_description,
    type.code AS type,
    typer.code AS referentietype,
    vw_waterlichamen.karakterschets,
    vw_waterlichamen.drinkwateronttrekking_jn,
    vw_waterlichamen.versie,
    vw_waterlichamen.versie_begintijd,
    vw_waterlichamen.versie_eindtijd,
    surface_water_body.article_43_comment AS article_43a_comment,
    surface_water_body.article_43_litref AS article_43a_litref,
    surface_water_body.article_43b_motivation,
    vw_waterlichamen."Gerelateerd_HydroObject"
   FROM (((surface_water_body
     LEFT JOIN vw_waterlichamen ON ((surface_water_body.swb_id = vw_waterlichamen.db_id)))
     JOIN sw_typology_type type ON ((type.styp_id = surface_water_body.sw_typology_id)))
     JOIN sw_typology_type typer ON ((typer.styp_id = surface_water_body.sw_target_typology_id)));


--
-- Name: vw_belastingen_owm_csv; Type: VIEW; Schema: public; Owner: -
--

CREATE VIEW vw_belastingen_owm_csv AS
 SELECT vw_oppervlaktewaterlichamen.identificatie AS "Oppervlaktewaterlichaam.Identificatie",
    vw_oppervlaktewaterlichamen.versie,
    sw_pressure_type.description AS "BelastingSoort",
    pressure_category_type.omschrijving AS "BelastingCategorie",
    swb_pressure.is_significant AS "SignificantJN",
    swb_pressure.function AS "Functie",
    swb_pressure.effect AS "Effecten",
    swb_pressure.remark AS "Opmerking"
   FROM vw_oppervlaktewaterlichamen,
    swb_pressure,
    sw_pressure_type,
    pressure_category_type
  WHERE ((vw_oppervlaktewaterlichamen.db_id = swb_pressure.swb_id) AND (sw_pressure_type.sprs_id = swb_pressure.sprs_id) AND (pressure_category_type.pcat_id = sw_pressure_type.pressure_category_id))
  ORDER BY vw_oppervlaktewaterlichamen.identificatie, swb_pressure.sprs_id DESC, pressure_category_type.omschrijving;


--
-- Name: vw_belastingen_owm_csv_nieuw; Type: VIEW; Schema: public; Owner: -
--

CREATE VIEW vw_belastingen_owm_csv_nieuw AS
 SELECT vw_oppervlaktewaterlichamen.identificatie AS "Oppervlaktewaterlichaam.Identificatie",
    vw_oppervlaktewaterlichamen.versie,
    sw_pressure_type.description AS "BelastingSoort",
    pressure_category_type.omschrijving AS "BelastingCategorie",
    swb_pressure.is_significant AS "SignificantJN",
    swb_pressure.remark AS "Opmerking",
    ( SELECT array_to_string(ARRAY( SELECT drivers.naam
                   FROM (domains.drivers
                     JOIN sw_pressure_type_driver ON (((drivers.driver_id = sw_pressure_type_driver.driver_id) AND (sw_pressure_type_driver.sprs_id = sw_pressure_type.sprs_id))))), ','::text) AS array_to_string) AS "Functie",
    ( SELECT array_to_string(ARRAY( SELECT impacts.naam
                   FROM (domains.impacts
                     JOIN swb_pressure_impact ON (((impacts.impact_id = swb_pressure_impact.impact_id) AND (swb_pressure_impact.swbp_id = swb_pressure.swbp_id))))), ','::text) AS array_to_string) AS "Impact"
   FROM vw_oppervlaktewaterlichamen,
    swb_pressure,
    sw_pressure_type,
    pressure_category_type
  WHERE ((vw_oppervlaktewaterlichamen.db_id = swb_pressure.swb_id) AND (sw_pressure_type.sprs_id = swb_pressure.sprs_id) AND (pressure_category_type.pcat_id = sw_pressure_type.pressure_category_id) AND (sw_pressure_type.d_eind IS NULL))
  ORDER BY vw_oppervlaktewaterlichamen.identificatie, swb_pressure.sprs_id DESC, pressure_category_type.omschrijving;


--
-- Name: vw_beschermd_gebied_richtlijn; Type: VIEW; Schema: public; Owner: -
--

CREATE VIEW vw_beschermd_gebied_richtlijn AS
 SELECT tempq.mtm_id,
    tempq.wpa_id,
    string_agg((tempq.code)::text, ', '::text) AS code,
    string_agg((tempq.description)::text, ', '::text) AS agg_richtlijn
   FROM ( SELECT DISTINCT ON (mma.mtm_id, wpa.last_change_time) mma.mtm_id,
            mpa.wpa_id,
            wpa.last_change_time,
            pat.code,
            pat.description
           FROM (((monitored_measure mma
             LEFT JOIN measure_per_man_protected_area mpa ON ((mma.mtm_id = mpa.mtm_id)))
             LEFT JOIN wfd_protected_area wpa ON ((wpa.wpa_id = mpa.wpa_id)))
             LEFT JOIN protected_area_type pat ON ((pat.pat_id = wpa.protected_area_type_id)))) tempq
  GROUP BY tempq.mtm_id, tempq.wpa_id;


--
-- Name: vw_beschermdegebieden; Type: VIEW; Schema: public; Owner: -
--

CREATE VIEW vw_beschermdegebieden AS
 SELECT hydro_object.hdo_id AS "DB_ID",
    hdo_names.name AS "Omschrijving",
    hydro_object.inspire_id_local_id AS "Identificatie",
    protected_area_type.description AS "Soort_Beschermd_Gebied",
    protected_area_type.code AS "Soort_Beschermd_Gebied_Code",
    wfd_protected_area.comment_value_status_prot_area AS "Toelichting",
    hydro_object.wkrv_id AS "Versie_ID",
    hydro_object.related_hdo_id AS "Gerelateerd_HydroObject"
   FROM (((((hydro_object
     LEFT JOIN hdo_names ON ((hdo_names.hdo_id = hydro_object.hdo_id)))
     JOIN wkr_version ON ((wkr_version.wkrv_id = hydro_object.wkrv_id)))
     LEFT JOIN management_regulation_or_restriction_zone ON ((management_regulation_or_restriction_zone.mrz_id = hydro_object.hdo_id)))
     JOIN wfd_protected_area ON ((wfd_protected_area.wpa_id = hydro_object.hdo_id)))
     JOIN protected_area_type ON ((protected_area_type.pat_id = wfd_protected_area.protected_area_type_id)));


--
-- Name: vw_beschermdegebieden_g; Type: VIEW; Schema: public; Owner: -
--

CREATE VIEW vw_beschermdegebieden_g AS
 SELECT hydro_object.hdo_id AS "DB_ID",
    hdo_names.name AS "Omschrijving",
    hydro_object.inspire_id_local_id AS "Identificatie",
    protected_area_type.description AS "Soort_Beschermd_Gebied",
    protected_area_type.code AS "Soort_Beschermd_Gebied_Code",
    wfd_protected_area.comment_value_status_prot_area AS "Toelichting",
    management_regulation_or_restriction_zone.geometry,
    geometrytype(management_regulation_or_restriction_zone.geometry) AS geometry_type,
    hydro_object.wkrv_id AS "Versie_ID",
    hydro_object.related_hdo_id AS "Gerelateerd_HydroObject"
   FROM (((((hydro_object
     LEFT JOIN hdo_names ON ((hdo_names.hdo_id = hydro_object.hdo_id)))
     JOIN wkr_version ON ((wkr_version.wkrv_id = hydro_object.wkrv_id)))
     LEFT JOIN management_regulation_or_restriction_zone ON ((management_regulation_or_restriction_zone.mrz_id = hydro_object.hdo_id)))
     JOIN wfd_protected_area ON ((wfd_protected_area.wpa_id = hydro_object.hdo_id)))
     JOIN protected_area_type ON ((protected_area_type.pat_id = wfd_protected_area.protected_area_type_id)))
UNION ALL
 SELECT hydro_object.hdo_id AS "DB_ID",
    hdo_names.name AS "Omschrijving",
    hydro_object.inspire_id_local_id AS "Identificatie",
    (('OnttrekkingMenselijkeConsumptie ('::text ||
        CASE
            WHEN ((hydro_object.hydro_object_type)::text = 'SurfaceWaterBody'::text) THEN 'Oppervlaktewater'::text
            ELSE 'Grondwater'::text
        END) || ')'::text) AS "Soort_Beschermd_Gebied",
    'A7'::text AS "Soort_Beschermd_Gebied_Code",
    NULL::character varying AS "Toelichting",
    mrz.geometry,
    geometrytype(mrz.geometry) AS geometry_type,
    hydro_object.wkrv_id AS "Versie_ID",
    hydro_object.related_hdo_id AS "Gerelateerd_HydroObject"
   FROM ((((hydro_object
     LEFT JOIN hdo_names ON ((hdo_names.hdo_id = hydro_object.hdo_id)))
     JOIN wkr_version ON ((wkr_version.wkrv_id = hydro_object.wkrv_id)))
     LEFT JOIN management_regulation_or_restriction_zone mrz ON ((mrz.mrz_id = hydro_object.hdo_id)))
     JOIN water_body ON ((water_body.wbd_id = hydro_object.hdo_id)))
  WHERE (water_body.is_article_7 IS TRUE);


--
-- Name: vw_beschermdegebieden_g_kaart; Type: VIEW; Schema: public; Owner: -
--

CREATE VIEW vw_beschermdegebieden_g_kaart AS
 SELECT hydro_object.hdo_id AS db_id,
    protected_area_type.code,
    management_regulation_or_restriction_zone.geometry,
    hydro_object.wkrv_id AS versie
   FROM (((((hydro_object
     LEFT JOIN hdo_names ON ((hdo_names.hdo_id = hydro_object.hdo_id)))
     JOIN wkr_version ON ((wkr_version.wkrv_id = hydro_object.wkrv_id)))
     LEFT JOIN management_regulation_or_restriction_zone ON ((management_regulation_or_restriction_zone.mrz_id = hydro_object.hdo_id)))
     JOIN wfd_protected_area ON ((wfd_protected_area.wpa_id = hydro_object.hdo_id)))
     JOIN protected_area_type ON ((protected_area_type.pat_id = wfd_protected_area.protected_area_type_id)));


--
-- Name: vw_beschermdegebieden_g_punt; Type: VIEW; Schema: public; Owner: -
--

CREATE VIEW vw_beschermdegebieden_g_punt AS
 SELECT hydro_object.hdo_id AS db_id,
    protected_area_type.code,
    management_regulation_or_restriction_zone.geometry,
    hydro_object.wkrv_id AS versie
   FROM (((((hydro_object
     LEFT JOIN hdo_names ON ((hdo_names.hdo_id = hydro_object.hdo_id)))
     JOIN wkr_version ON ((wkr_version.wkrv_id = hydro_object.wkrv_id)))
     LEFT JOIN management_regulation_or_restriction_zone ON ((management_regulation_or_restriction_zone.mrz_id = hydro_object.hdo_id)))
     JOIN wfd_protected_area ON ((wfd_protected_area.wpa_id = hydro_object.hdo_id)))
     JOIN protected_area_type ON ((protected_area_type.pat_id = wfd_protected_area.protected_area_type_id)))
  WHERE (geometrytype(management_regulation_or_restriction_zone.geometry) ~~ '%POINT'::text);


--
-- Name: vw_beschermdegebieden_g_vlak; Type: VIEW; Schema: public; Owner: -
--

CREATE VIEW vw_beschermdegebieden_g_vlak AS
 SELECT hydro_object.hdo_id AS db_id,
    protected_area_type.code,
    management_regulation_or_restriction_zone.geometry,
    hydro_object.wkrv_id AS versie
   FROM (((((hydro_object
     LEFT JOIN hdo_names ON ((hdo_names.hdo_id = hydro_object.hdo_id)))
     JOIN wkr_version ON ((wkr_version.wkrv_id = hydro_object.wkrv_id)))
     LEFT JOIN management_regulation_or_restriction_zone ON ((management_regulation_or_restriction_zone.mrz_id = hydro_object.hdo_id)))
     JOIN wfd_protected_area ON ((wfd_protected_area.wpa_id = hydro_object.hdo_id)))
     JOIN protected_area_type ON ((protected_area_type.pat_id = wfd_protected_area.protected_area_type_id)))
  WHERE (geometrytype(management_regulation_or_restriction_zone.geometry) = ANY (ARRAY['POLYGON'::text, 'MULTIPOLYGON'::text]));


--
-- Name: vw_beschermdegebieden_shape; Type: VIEW; Schema: public; Owner: -
--

CREATE VIEW vw_beschermdegebieden_shape AS
 SELECT DISTINCT ON (hydro_object.inspire_id_local_id) hydro_object.inspire_id_local_id AS "IDENT",
    hdo_names.name AS "NAAM",
    protected_area_type.description AS "SOORT",
    wfd_protected_area.comment_value_status_prot_area AS "TOELICHT",
    management_regulation_or_restriction_zone.geometry
   FROM (((((hydro_object
     LEFT JOIN hdo_names ON ((hdo_names.hdo_id = hydro_object.hdo_id)))
     JOIN wkr_version ON ((wkr_version.wkrv_id = hydro_object.wkrv_id)))
     LEFT JOIN management_regulation_or_restriction_zone ON ((management_regulation_or_restriction_zone.mrz_id = hydro_object.hdo_id)))
     JOIN wfd_protected_area ON ((wfd_protected_area.wpa_id = hydro_object.hdo_id)))
     JOIN protected_area_type ON ((protected_area_type.pat_id = wfd_protected_area.protected_area_type_id)))
  ORDER BY hydro_object.inspire_id_local_id, wkr_version.wkrv_id DESC;


--
-- Name: vw_chemischestof_groepen; Type: VIEW; Schema: public; Owner: -
--

CREATE VIEW vw_chemischestof_groepen AS
 SELECT substance_group.ssg_id AS "DB_ID",
    substance_group.name AS "Groepsnaam",
    substance_group.group_type AS "Type",
    chemische_stof_type.chs_id AS "ChemischeStof_DB_ID",
    chemische_stof_type.code AS "ChemischeStof_Code",
    chemische_stof_type.naam AS "ChemischeStof_Omschrijving",
    chemische_stof_type.cas_nr AS "ChemischeStof_CASnr"
   FROM chemische_stof_type,
    substance_group,
    substance_group_element
  WHERE ((chemische_stof_type.chs_id = substance_group_element.chs_id) AND (substance_group.ssg_id = substance_group_element.ssge_id))
  ORDER BY ("position"('S,G,I'::text, (substance_group.group_type)::text)), substance_group.name, chemische_stof_type.code;


--
-- Name: vw_comment_table_view; Type: VIEW; Schema: public; Owner: -
--

CREATE VIEW vw_comment_table_view AS
 SELECT dcn.objoid AS object_id,
    cls.relname AS tabel_of_view_naam,
    dcn.description AS commentaar
   FROM (pg_description dcn
     JOIN pg_class cls ON ((cls.relfilenode = dcn.objoid)));


--
-- Name: VIEW vw_comment_table_view; Type: COMMENT; Schema: public; Owner: -
--

COMMENT ON VIEW vw_comment_table_view IS 'Hiermee kun je het commentaar bij een tabel of view ophalen en inzien.';


--
-- Name: vw_deelstroomgebieddistricten; Type: VIEW; Schema: public; Owner: -
--

CREATE VIEW vw_deelstroomgebieddistricten AS
 SELECT hydro_object.hdo_id AS "DB_ID",
    hydro_object.inspire_id_local_id AS "Identificatie",
    hdo_names.name AS omschrijving,
    management_regulation_or_restriction_zone.geometry,
    river_basin_disrict.area_value AS "Oppervlakte_NumeriekeWaarde",
    eenheid_type.code AS "Oppervlakte_Eenheid_Code",
    eenheid_type.omschrijving AS "Oppervlakte_Eenheid_Omschrijving",
    wkr_version.wkrv_id AS wkr_versie,
    wkr_version.begin_lifespan_version AS wkr_beginversie,
    wkr_version.end_lifespan_version AS wkr_eindversie,
    hydro_object.related_hdo_id AS "Gerelateerd_HydroObject"
   FROM (((((hydro_object
     LEFT JOIN hdo_names ON ((hdo_names.hdo_id = hydro_object.hdo_id)))
     JOIN management_regulation_or_restriction_zone ON ((hydro_object.hdo_id = management_regulation_or_restriction_zone.mrz_id)))
     JOIN river_basin_disrict ON ((hydro_object.hdo_id = river_basin_disrict.rbd_id)))
     JOIN eenheid_type ON ((eenheid_type.eenh_id = river_basin_disrict.area_uom_id)))
     JOIN wkr_version ON ((wkr_version.wkrv_id = hydro_object.wkrv_id)))
  WHERE (river_basin_disrict.part_of_district IS NOT NULL);


--
-- Name: vw_deelstroomgebieddistricten_de_g; Type: VIEW; Schema: public; Owner: -
--

CREATE VIEW vw_deelstroomgebieddistricten_de_g AS
 SELECT hydro_object.hdo_id AS "DB_ID",
    hydro_object.inspire_id_local_id AS "Identificatie",
    hdo_names.name AS omschrijving,
    management_regulation_or_restriction_zone.geometry,
    hydro_object.wkrv_id AS wkr_versie
   FROM (((hydro_object
     LEFT JOIN hdo_names ON ((hdo_names.hdo_id = hydro_object.hdo_id)))
     JOIN management_regulation_or_restriction_zone ON ((hydro_object.hdo_id = management_regulation_or_restriction_zone.mrz_id)))
     JOIN river_basin_disrict ON ((hydro_object.hdo_id = river_basin_disrict.rbd_id)))
  WHERE ((river_basin_disrict.part_of_district IS NULL) AND (river_basin_disrict.international_rbd IS NULL));


--
-- Name: vw_deelstroomgebieddistricten_g; Type: VIEW; Schema: public; Owner: -
--

CREATE VIEW vw_deelstroomgebieddistricten_g AS
 SELECT hydro_object.hdo_id AS "DB_ID",
    hydro_object.inspire_id_local_id AS "Identificatie",
    hdo_names.name AS omschrijving,
    management_regulation_or_restriction_zone.geometry,
    hydro_object.wkrv_id AS wkr_versie
   FROM (((hydro_object
     LEFT JOIN hdo_names ON ((hdo_names.hdo_id = hydro_object.hdo_id)))
     JOIN management_regulation_or_restriction_zone ON ((hydro_object.hdo_id = management_regulation_or_restriction_zone.mrz_id)))
     JOIN river_basin_disrict ON ((hydro_object.hdo_id = river_basin_disrict.rbd_id)))
  WHERE (river_basin_disrict.part_of_district IS NOT NULL);


--
-- Name: vw_deelstroomgebieddistricten_shape; Type: VIEW; Schema: public; Owner: -
--

CREATE VIEW vw_deelstroomgebieddistricten_shape AS
 SELECT DISTINCT ON (hydro_object.inspire_id_local_id) hydro_object.inspire_id_local_id AS "IDENT",
    hdo_names.name AS "NAAM",
    management_regulation_or_restriction_zone.geometry,
    river_basin_disrict.area_value AS "OPP",
    eenheid_type.code AS "OPP_EENH"
   FROM (((((hydro_object
     LEFT JOIN hdo_names ON ((hdo_names.hdo_id = hydro_object.hdo_id)))
     JOIN management_regulation_or_restriction_zone ON ((hydro_object.hdo_id = management_regulation_or_restriction_zone.mrz_id)))
     JOIN river_basin_disrict ON ((hydro_object.hdo_id = river_basin_disrict.rbd_id)))
     JOIN eenheid_type ON ((eenheid_type.eenh_id = river_basin_disrict.area_uom_id)))
     JOIN wkr_version ON ((wkr_version.wkrv_id = hydro_object.wkrv_id)))
  WHERE (river_basin_disrict.part_of_district IS NOT NULL)
  ORDER BY hydro_object.inspire_id_local_id, wkr_version.wkrv_id DESC;


--
-- Name: vw_doelen_owm; Type: VIEW; Schema: public; Owner: -
--

CREATE VIEW vw_doelen_owm AS
 SELECT DISTINCT ON (norm_value.nrmv_id, vw_waargenomen_eigenschap."DB_ID", classification_type.description) norm_value.nrmv_id AS "DB_ID",
    vw_waterlichamen.db_id AS "Waterlichaam_DB_ID",
    vw_waterlichamen.identificatie AS "Waterlichaam_identificatie",
    level_of_area_type.loa_id AS "Definitie_niveau_code",
    level_of_area_type.description AS "Definitie_niveau_omschrijving",
    compartiment_type.code AS "Compartiment_Code",
    compartiment_type.description AS "Compartiment_Omschrijving",
    vw_waargenomen_eigenschap."DB_ID" AS "Waargenomen_Eigenschap_DB_ID",
    vw_waargenomen_eigenschap."Tpering_Code",
    vw_waargenomen_eigenschap."Typering_Omschrijving",
    vw_waargenomen_eigenschap."Grootheid_Code",
    vw_waargenomen_eigenschap."Grootheid_Omschrijving",
    vw_waargenomen_eigenschap."ChemischeStof_code",
    vw_waargenomen_eigenschap."ChemischeStof_Omschrijving",
    vw_waargenomen_eigenschap."Object_Omschrijving",
    vw_waargenomen_eigenschap."Object_Code",
    vw_waargenomen_eigenschap."Taxon_Naam",
    vw_waargenomen_eigenschap."Taxon_Auteur",
    vw_waargenomen_eigenschap."Hoedanigheid_Code",
    vw_waargenomen_eigenschap."Hoedanigheid_Omschrijving",
    waarde_bewerkings_methode_type.code AS "Waardebewerkingsmethode_Code",
    waarde_bewerkings_methode_type.omschrijving AS "Waardebewerkingsmethode_Omschrijving",
    eenheid_type.code AS "Eenheid_Code",
    eenheid_type.omschrijving AS "Eenheid_Omschrijving",
    classification_type.description AS "Classificatie",
    bepaling_grens_type.omschrijving AS "Ondergrens_BepalingsGrens",
    norm_value.lowerbound_value AS "Ondergrens_Waarde",
    bgt.omschrijving AS "Bovengrens_BepalingsGrens",
    norm_value.upperbound_value AS "Bovengrens_Waarde",
    norm_value.begin_lifespan_version AS "Begindatum",
    norm_value.end_lifespan_version AS "Einddatum",
    norm_value.opmerking AS "Opmerking",
    norm_groep_type.omschrijving AS "Normgroep",
    norm.wkrv_id AS "Versie_ID",
    date_part('year'::text, norm_value.begin_lifespan_version) AS "Rapportagejaar",
    norm_value.nrmv_id AS norm_value_id
   FROM ((((((((((((norm
     LEFT JOIN norm_feature ON ((norm_feature.nrm_id = norm.nrm_id)))
     LEFT JOIN norm_value ON ((norm_value.nrm_id = norm.nrm_id)))
     LEFT JOIN vw_waargenomen_eigenschap ON ((vw_waargenomen_eigenschap."DB_ID" = norm.observed_property)))
     LEFT JOIN vw_waterlichamen ON ((vw_waterlichamen.db_id = norm_feature.hdo_id)))
     JOIN level_of_area_type ON ((level_of_area_type.loa_id = norm.defined_at_level_id)))
     JOIN norm_groep_type ON ((norm_groep_type.nmgp_id = norm.norm_groep_id)))
     JOIN waarde_bewerkings_methode_type ON ((waarde_bewerkings_methode_type.wbm_id = norm_value.value_processing_method)))
     JOIN eenheid_type ON ((eenheid_type.eenh_id = norm_value.lowerbound_uom_id)))
     JOIN compartiment_type ON ((compartiment_type.cptm_id = norm_value.cptm_id)))
     JOIN classification_type ON ((classification_type.cls_id = norm_value.norm_klasse_id)))
     LEFT JOIN bepaling_grens_type ON ((bepaling_grens_type.bpg_id = norm_value.lowerbound_limit_symbol_id)))
     LEFT JOIN bepaling_grens_type bgt ON ((bgt.bpg_id = norm_value.upperbound_limit_symbol_id)))
  WHERE ((level_of_area_type.loa_id = 5) AND (norm_groep_type.nmgp_id = 7) AND ((norm_value.end_lifespan_version IS NULL) OR (norm_value.end_lifespan_version >= now())))
  ORDER BY norm_value.nrmv_id, vw_waargenomen_eigenschap."DB_ID", classification_type.description, norm.last_change_time DESC, norm.wkrv_id DESC;


--
-- Name: vw_doelen_owm_csv; Type: VIEW; Schema: public; Owner: -
--

CREATE VIEW vw_doelen_owm_csv AS
 SELECT vw_oppervlaktewaterlichamen.identificatie AS "Oppervlaktewaterlichaam.Identificatie",
    vw_oppervlaktewaterlichamen.versie AS "Versie",
    compartiment_type.code AS "Compartiment.Code",
    compartiment_type.description AS "Compartiment.Omschrijving",
    vw_waargenomen_eigenschap."Tpering_Code" AS "Typering.Code",
    vw_waargenomen_eigenschap."Typering_Omschrijving" AS "Typering.Omschrijving",
    vw_waargenomen_eigenschap."Grootheid_Code" AS "Grootheid.Code",
    vw_waargenomen_eigenschap."Grootheid_Omschrijving" AS "Grootheid.Omschrijving",
    vw_waargenomen_eigenschap."ChemischeStof_code" AS "ChemischeStof.Code",
    vw_waargenomen_eigenschap."ChemischeStof_Omschrijving" AS "ChemischeStof.Omschrijving",
    vw_waargenomen_eigenschap."Hoedanigheid_Code" AS "Hoedanigheid.Code",
    vw_waargenomen_eigenschap."Hoedanigheid_Omschrijving" AS "Hoedanigheid.Omschrijving",
    waarde_bewerkings_methode_type.code AS "Waardebewerkingsmethode.Code",
    waarde_bewerkings_methode_type.omschrijving AS "Waardebewerkingsmethode.Omschrijving",
    eenheid_type.code AS "Eenheid.Code",
    eenheid_type.omschrijving AS "Eenheid.Omschrijving",
    classification_type.description AS "Classificatie",
    bepaling_grens_type.omschrijving AS "Ondergrens.BepalingsGrens",
    norm_value.lowerbound_value AS "Ondergrens.NumeriekeWaarde",
    bgt.omschrijving AS "Bovengrens.BepalingsGrens",
    norm_value.upperbound_value AS "Bovengrens.NumeriekeWaarde",
    norm_value.begin_lifespan_version AS "Begindatum",
    norm_value.end_lifespan_version AS "Einddatum"
   FROM (((((((((((norm
     LEFT JOIN norm_feature ON ((norm_feature.nrm_id = norm.nrm_id)))
     LEFT JOIN norm_value ON ((norm_value.nrm_id = norm.nrm_id)))
     LEFT JOIN vw_waargenomen_eigenschap ON ((vw_waargenomen_eigenschap."DB_ID" = norm.observed_property)))
     LEFT JOIN vw_oppervlaktewaterlichamen ON ((vw_oppervlaktewaterlichamen.db_id = norm_feature.hdo_id)))
     JOIN norm_groep_type ON ((norm_groep_type.nmgp_id = norm.norm_groep_id)))
     JOIN waarde_bewerkings_methode_type ON ((waarde_bewerkings_methode_type.wbm_id = norm_value.value_processing_method)))
     JOIN eenheid_type ON ((eenheid_type.eenh_id = norm_value.lowerbound_uom_id)))
     JOIN compartiment_type ON ((compartiment_type.cptm_id = norm_value.cptm_id)))
     JOIN classification_type ON ((classification_type.cls_id = norm_value.norm_klasse_id)))
     LEFT JOIN bepaling_grens_type ON ((bepaling_grens_type.bpg_id = norm_value.lowerbound_limit_symbol_id)))
     LEFT JOIN bepaling_grens_type bgt ON ((bgt.bpg_id = norm_value.upperbound_limit_symbol_id)))
  WHERE ((norm_groep_type.nmgp_id = 7) AND ((norm_value.end_lifespan_version IS NULL) OR (norm_value.end_lifespan_version >= now())))
  ORDER BY vw_oppervlaktewaterlichamen.identificatie, vw_waargenomen_eigenschap."DB_ID", classification_type.description, norm_value.end_lifespan_version, norm_value.begin_lifespan_version;


--
-- Name: vw_doelen_owm_csv_nieuw; Type: VIEW; Schema: public; Owner: -
--

CREATE VIEW vw_doelen_owm_csv_nieuw AS
 WITH doelen AS (
         SELECT DISTINCT ON (norm_feature.hdo_id, norm_value.nrmv_id, vw_waargenomen_eigenschap_db_id."DB_ID", classification_type.description) norm_feature.hdo_id,
            compartiment_type.code AS "Compartiment.Code",
            compartiment_type.description AS "Compartiment.Omschrijving",
            vw_waargenomen_eigenschap_db_id."Tpering_Code" AS "Typering.Code",
            vw_waargenomen_eigenschap_db_id."Typering_Omschrijving" AS "Typering.Omschrijving",
            vw_waargenomen_eigenschap_db_id."Grootheid_Code" AS "Grootheid.Code",
            vw_waargenomen_eigenschap_db_id."Grootheid_Omschrijving" AS "Grootheid.Omschrijving",
            vw_waargenomen_eigenschap_db_id."DB_ID",
            vw_waargenomen_eigenschap_db_id."ChemischeStof_code" AS "ChemischeStof.Code",
            vw_waargenomen_eigenschap_db_id."ChemischeStof_Omschrijving" AS "ChemischeStof.Omschrijving",
            vw_waargenomen_eigenschap_db_id."Hoedanigheid_Code" AS "Hoedanigheid.Code",
            vw_waargenomen_eigenschap_db_id."Hoedanigheid_Omschrijving" AS "Hoedanigheid.Omschrijving",
            waarde_bewerkings_methode_type.code AS "Waardebewerkingsmethode.Code",
            waarde_bewerkings_methode_type.omschrijving AS "Waardebewerkingsmethode.Omschrijving",
            eenheid_type.code AS "Eenheid.Code",
            eenheid_type.omschrijving AS "Eenheid.Omschrijving",
            classification_type.description AS "Classificatie",
            bepaling_grens_type.omschrijving AS "Ondergrens.BepalingsGrens",
            norm_value.lowerbound_value AS "Ondergrens.Waarde",
            bgt.omschrijving AS "Bovengrens.BepalingsGrens",
            norm_value.upperbound_value AS "Bovengrens.Waarde",
            norm.wkrv_id AS versie,
            date_part('year'::text, norm_value.begin_lifespan_version) AS "Rapportagejaar"
           FROM (((((((((((norm_value
             LEFT JOIN norm ON ((norm_value.nrm_id = norm.nrm_id)))
             LEFT JOIN norm_feature ON ((norm_feature.nrm_id = norm.nrm_id)))
             LEFT JOIN vw_waargenomen_eigenschap_db_id ON ((vw_waargenomen_eigenschap_db_id."DB_ID" = norm.observed_property)))
             LEFT JOIN level_of_area_type ON ((level_of_area_type.loa_id = norm.defined_at_level_id)))
             LEFT JOIN norm_groep_type ON ((norm_groep_type.nmgp_id = norm.norm_groep_id)))
             LEFT JOIN waarde_bewerkings_methode_type ON ((waarde_bewerkings_methode_type.wbm_id = norm_value.value_processing_method)))
             LEFT JOIN eenheid_type ON ((eenheid_type.eenh_id = norm_value.lowerbound_uom_id)))
             LEFT JOIN compartiment_type ON ((compartiment_type.cptm_id = norm_value.cptm_id)))
             LEFT JOIN classification_type ON ((classification_type.cls_id = norm_value.norm_klasse_id)))
             LEFT JOIN bepaling_grens_type ON ((bepaling_grens_type.bpg_id = norm_value.lowerbound_limit_symbol_id)))
             LEFT JOIN bepaling_grens_type bgt ON ((bgt.bpg_id = norm_value.upperbound_limit_symbol_id)))
          WHERE ((level_of_area_type.loa_id = 5) AND (norm_groep_type.nmgp_id = 7) AND ((norm_value.end_lifespan_version IS NULL) OR (norm_value.end_lifespan_version >= now())))
          ORDER BY norm_feature.hdo_id, norm_value.nrmv_id, vw_waargenomen_eigenschap_db_id."DB_ID", classification_type.description, norm.last_change_time DESC, norm.wkrv_id DESC
        )
 SELECT vw_oppervlaktewaterlichamen.identificatie AS "Waterlichaam.Identificatie",
    vw_oppervlaktewaterlichamen.type AS "Watertype",
    vw_oppervlaktewaterlichamen.referentietype AS "Doeltype",
    vw_oppervlaktewaterlichamen.waterlichaam_status AS "Waterlichaam.Status",
    doelen."Compartiment.Code",
    doelen."Compartiment.Omschrijving",
    doelen."Typering.Code",
    doelen."Typering.Omschrijving",
    doelen."Grootheid.Code",
    doelen."Grootheid.Omschrijving",
    doelen."ChemischeStof.Code",
    doelen."ChemischeStof.Omschrijving",
    doelen."Hoedanigheid.Code",
    doelen."Hoedanigheid.Omschrijving",
    doelen."Waardebewerkingsmethode.Code",
    doelen."Waardebewerkingsmethode.Omschrijving",
    doelen."Eenheid.Code",
    doelen."Eenheid.Omschrijving",
    doelen."Classificatie",
    doelen."Ondergrens.BepalingsGrens",
    doelen."Ondergrens.Waarde",
    doelen."Bovengrens.BepalingsGrens",
    doelen."Bovengrens.Waarde",
    doelen.versie,
    doelen."Rapportagejaar"
   FROM (vw_oppervlaktewaterlichamen
     LEFT JOIN doelen ON ((vw_oppervlaktewaterlichamen.db_id = doelen.hdo_id)));


--
-- Name: vw_krw_kwaliteitselement; Type: VIEW; Schema: public; Owner: -
--

CREATE VIEW vw_krw_kwaliteitselement AS
 SELECT wfd_qe_swtype.qesw_id AS "DB_ID",
    sw_typology_type.code AS "Watertype_Code",
    sw_typology_type.description AS "Watertype_Omschrijving",
    sw_typology_type.is_freshwater AS "Is_Zoetwater",
    vw_waargenomen_eigenschap."DB_ID" AS "Waargenomen_Eigenschap_DB_ID",
    wfd_qe_swtype.name AS "Kwaliteitselement_Naam",
    vw_waargenomen_eigenschap."Tpering_Code",
    vw_waargenomen_eigenschap."Typering_Omschrijving",
    vw_waargenomen_eigenschap."Grootheid_Code",
    vw_waargenomen_eigenschap."Grootheid_Omschrijving",
    vw_waargenomen_eigenschap."ChemischeStof_code",
    vw_waargenomen_eigenschap."ChemischeStof_Omschrijving",
    vw_waargenomen_eigenschap."ChemischeStof_CASnr",
    vw_waargenomen_eigenschap."Hoedanigheid_Code",
    vw_waargenomen_eigenschap."Hoedanigheid_Omschrijving",
    we2."DB_ID" AS "Onderdeel_van_Typering_DB_ID",
    we2."Tpering_Code" AS "Onderdeel_van_Typering_Code",
    we2."Typering_Omschrijving" AS "Onderdeel_van_Typering_Omschrijving",
    wfd_qe_swtype.main_group AS "Is_hoofdgroep",
    wfd_qe_swtype.is_applicable AS "Is_van_toepassing",
    wfd_qe_swtype.is_excemption AS "Is_artikel_4",
    wfd_qe_swtype.clsg_id AS "ClassifciatieGroep_DB_ID",
    classification_group_type.description AS "ClassificatieGroep_Omschrijving"
   FROM ((((wfd_qe_swtype
     LEFT JOIN sw_typology_type ON ((sw_typology_type.styp_id = wfd_qe_swtype.swt_id)))
     LEFT JOIN vw_waargenomen_eigenschap ON ((vw_waargenomen_eigenschap."DB_ID" = wfd_qe_swtype.opt_id)))
     LEFT JOIN vw_waargenomen_eigenschap we2 ON ((we2."DB_ID" = wfd_qe_swtype.part_of_opt_id)))
     LEFT JOIN classification_group_type ON ((wfd_qe_swtype.clsg_id = classification_group_type.clsg_id)))
  ORDER BY sw_typology_type.code, vw_waargenomen_eigenschap."Tpering_Code", vw_waargenomen_eigenschap."Grootheid_Code", vw_waargenomen_eigenschap."ChemischeStof_code";


--
-- Name: vw_doelen_owm_dgrw; Type: VIEW; Schema: public; Owner: -
--

CREATE VIEW vw_doelen_owm_dgrw AS
 SELECT DISTINCT ON (norm_value.nrmv_id, vw_waargenomen_eigenschap_db_id."DB_ID", classification_type.description) vw_waterlichamen.omschrijving AS "Waterlichaam_Naam",
        CASE
            WHEN (namespace_type.ns_id >= 99) THEN namespace_type.descrption
            ELSE vw_competent_authority."Omschrijving"
        END AS "Waterbeheerder_omschrijving",
    "left"((vw_oppervlaktewaterlichamen.stroomgebieddistrict)::text, 4) AS "Stroomgebieddistrict",
    vw_oppervlaktewaterlichamen.type AS watertype,
    vw_oppervlaktewaterlichamen.referentietype AS doeltype,
    vw_oppervlaktewaterlichamen.waterlichaam_status AS "Waterlichaam_Status",
        CASE
            WHEN ((vw_waargenomen_eigenschap_db_id."Grootheid_Omschrijving")::text = '(massa)Concentratie'::text) THEN concat(vw_waargenomen_eigenschap_db_id."Typering_Omschrijving", vw_waargenomen_eigenschap_db_id."ChemischeStof_Omschrijving")
            ELSE concat(vw_waargenomen_eigenschap_db_id."Typering_Omschrijving", vw_waargenomen_eigenschap_db_id."Grootheid_Omschrijving")
        END AS "BeoordeeldeParameter",
    compartiment_type.code AS "Compartiment_Code",
    compartiment_type.description AS "Compartiment_Omschrijving",
    vw_waargenomen_eigenschap_db_id."DB_ID" AS "Waargenomen_Eigenschap_DB_ID",
    vw_waargenomen_eigenschap_db_id."Tpering_Code",
    vw_waargenomen_eigenschap_db_id."Typering_Omschrijving",
    vw_waargenomen_eigenschap_db_id."Grootheid_Code",
    vw_waargenomen_eigenschap_db_id."Grootheid_Omschrijving",
    vw_waargenomen_eigenschap_db_id."ChemischeStof_code",
    vw_waargenomen_eigenschap_db_id."ChemischeStof_Omschrijving",
    vw_waargenomen_eigenschap_db_id."Hoedanigheid_Code",
    vw_waargenomen_eigenschap_db_id."Hoedanigheid_Omschrijving",
    waarde_bewerkings_methode_type.code AS "Waardebewerkingsmethode_Code",
    waarde_bewerkings_methode_type.omschrijving AS "Waardebewerkingsmethode_Omschrijving",
    eenheid_type.code AS "Eenheid_Code",
    eenheid_type.omschrijving AS "Eenheid_Omschrijving",
    classification_type.description AS "Classificatie",
    bepaling_grens_type.omschrijving AS "Ondergrens_BepalingsGrens",
    norm_value.lowerbound_value AS "Ondergrens_Waarde",
    bgt.omschrijving AS "Bovengrens_BepalingsGrens",
    norm_value.upperbound_value AS "Bovengrens_Waarde",
    norm.wkrv_id AS "Versie_ID",
        CASE
            WHEN (krw_kwal."Is_van_toepassing" IS TRUE) THEN true
            ELSE false
        END AS "KWAL_ELEMENT",
    date_part('year'::text, norm_value.begin_lifespan_version) AS "Rapportagejaar",
    vw_waterlichamen.identificatie AS "Waterlichaam_identificatie",
    vw_waterlichamen.omschrijving AS "Waterlichaam_naam"
   FROM ((((((((((((((((((norm_value
     LEFT JOIN norm ON ((norm_value.nrm_id = norm.nrm_id)))
     LEFT JOIN norm_feature ON ((norm_feature.nrm_id = norm.nrm_id)))
     LEFT JOIN vw_waargenomen_eigenschap_db_id ON ((vw_waargenomen_eigenschap_db_id."DB_ID" = norm.observed_property)))
     LEFT JOIN vw_waterlichamen ON ((vw_waterlichamen.db_id = norm_feature.hdo_id)))
     LEFT JOIN vw_oppervlaktewaterlichamen ON ((vw_oppervlaktewaterlichamen.db_id = norm_feature.hdo_id)))
     LEFT JOIN level_of_area_type ON ((level_of_area_type.loa_id = norm.defined_at_level_id)))
     LEFT JOIN norm_groep_type ON ((norm_groep_type.nmgp_id = norm.norm_groep_id)))
     LEFT JOIN waarde_bewerkings_methode_type ON ((waarde_bewerkings_methode_type.wbm_id = norm_value.value_processing_method)))
     LEFT JOIN eenheid_type ON ((eenheid_type.eenh_id = norm_value.lowerbound_uom_id)))
     LEFT JOIN compartiment_type ON ((compartiment_type.cptm_id = norm_value.cptm_id)))
     LEFT JOIN classification_type ON ((classification_type.cls_id = norm_value.norm_klasse_id)))
     LEFT JOIN bepaling_grens_type ON ((bepaling_grens_type.bpg_id = norm_value.lowerbound_limit_symbol_id)))
     LEFT JOIN bepaling_grens_type bgt ON ((bgt.bpg_id = norm_value.upperbound_limit_symbol_id)))
     LEFT JOIN namespace_type ON ((namespace_type.ns_id = vw_waterlichamen.waterbeheerder_code)))
     JOIN competentauthority_namespacetype ON ((competentauthority_namespacetype.ns_id = vw_waterlichamen.waterbeheerder_code)))
     JOIN vw_competent_authority ON ((vw_competent_authority."DB_ID" = competentauthority_namespacetype.ore_id)))
     LEFT JOIN ( SELECT substance_group_element.chs_id,
            substance_group_element.ssge_id
           FROM substance_group_element
          WHERE (substance_group_element.ssge_id = 3125)) ssg_3125 ON ((ssg_3125.chs_id = vw_waargenomen_eigenschap_db_id."ChemischeStof_DB_ID")))
     LEFT JOIN vw_krw_kwaliteitselement krw_kwal ON ((((krw_kwal."Watertype_Code")::text = (vw_oppervlaktewaterlichamen.referentietype)::text) AND (krw_kwal."Waargenomen_Eigenschap_DB_ID" = vw_waargenomen_eigenschap_db_id."DB_ID"))))
  WHERE ((level_of_area_type.loa_id = 5) AND (norm_groep_type.nmgp_id = 7) AND ((norm_value.end_lifespan_version IS NULL) OR (norm_value.end_lifespan_version >= now())))
  ORDER BY norm_value.nrmv_id, vw_waargenomen_eigenschap_db_id."DB_ID", classification_type.description, norm.last_change_time DESC, norm.wkrv_id DESC;


--
-- Name: vw_doelen_owm_dgrw_nieuw; Type: VIEW; Schema: public; Owner: -
--

CREATE VIEW vw_doelen_owm_dgrw_nieuw AS
 SELECT DISTINCT ON (norm_value.nrmv_id, vw_waargenomen_eigenschap_db_id."DB_ID", classification_type.description) vw_waterlichamen.omschrijving AS "Waterlichaam_Naam",
        CASE
            WHEN (namespace_type.ns_id >= 99) THEN namespace_type.descrption
            ELSE vw_competent_authority."Omschrijving"
        END AS "Waterbeheerder_omschrijving",
    "left"((vw_oppervlaktewaterlichamen.stroomgebieddistrict)::text, 4) AS "Stroomgebieddistrict",
    vw_oppervlaktewaterlichamen.type AS watertype,
    vw_oppervlaktewaterlichamen.referentietype AS doeltype,
    vw_oppervlaktewaterlichamen.waterlichaam_status AS "Waterlichaam_Status",
        CASE
            WHEN ((vw_waargenomen_eigenschap_db_id."Grootheid_Omschrijving")::text = '(massa)Concentratie'::text) THEN concat(vw_waargenomen_eigenschap_db_id."Typering_Omschrijving", vw_waargenomen_eigenschap_db_id."ChemischeStof_Omschrijving")
            ELSE concat(vw_waargenomen_eigenschap_db_id."Typering_Omschrijving", vw_waargenomen_eigenschap_db_id."Grootheid_Omschrijving")
        END AS "BeoordeeldeParameter",
    compartiment_type.code AS "Compartiment_Code",
    compartiment_type.description AS "Compartiment_Omschrijving",
    vw_waargenomen_eigenschap_db_id."DB_ID" AS "Waargenomen_Eigenschap_DB_ID",
    vw_waargenomen_eigenschap_db_id."Tpering_Code",
    vw_waargenomen_eigenschap_db_id."Typering_Omschrijving",
    vw_waargenomen_eigenschap_db_id."Grootheid_Code",
    vw_waargenomen_eigenschap_db_id."Grootheid_Omschrijving",
    vw_waargenomen_eigenschap_db_id."ChemischeStof_code",
    vw_waargenomen_eigenschap_db_id."ChemischeStof_Omschrijving",
    vw_waargenomen_eigenschap_db_id."Hoedanigheid_Code",
    vw_waargenomen_eigenschap_db_id."Hoedanigheid_Omschrijving",
    waarde_bewerkings_methode_type.code AS "Waardebewerkingsmethode_Code",
    waarde_bewerkings_methode_type.omschrijving AS "Waardebewerkingsmethode_Omschrijving",
    eenheid_type.code AS "Eenheid_Code",
    eenheid_type.omschrijving AS "Eenheid_Omschrijving",
    classification_type.description AS "Classificatie",
    bepaling_grens_type.omschrijving AS "Ondergrens_BepalingsGrens",
    norm_value.lowerbound_value AS "Ondergrens_Waarde",
    bgt.omschrijving AS "Bovengrens_BepalingsGrens",
    norm_value.upperbound_value AS "Bovengrens_Waarde",
    norm.wkrv_id AS "Versie_ID",
        CASE
            WHEN (krw_kwal."Is_van_toepassing" IS TRUE) THEN true
            ELSE false
        END AS "KWAL_ELEMENT",
    date_part('year'::text, norm_value.begin_lifespan_version) AS "Rapportagejaar",
    vw_waterlichamen.identificatie AS "Waterlichaam_identificatie",
    vw_waterlichamen.omschrijving AS "Waterlichaam_naam"
   FROM ((((((((((((((((((norm_value
     LEFT JOIN norm ON ((norm_value.nrm_id = norm.nrm_id)))
     LEFT JOIN norm_feature ON ((norm_feature.nrm_id = norm.nrm_id)))
     LEFT JOIN vw_waargenomen_eigenschap_db_id ON ((vw_waargenomen_eigenschap_db_id."DB_ID" = norm.observed_property)))
     LEFT JOIN vw_waterlichamen ON ((vw_waterlichamen.db_id = norm_feature.hdo_id)))
     LEFT JOIN vw_oppervlaktewaterlichamen ON ((vw_oppervlaktewaterlichamen.db_id = norm_feature.hdo_id)))
     LEFT JOIN level_of_area_type ON ((level_of_area_type.loa_id = norm.defined_at_level_id)))
     LEFT JOIN norm_groep_type ON ((norm_groep_type.nmgp_id = norm.norm_groep_id)))
     LEFT JOIN waarde_bewerkings_methode_type ON ((waarde_bewerkings_methode_type.wbm_id = norm_value.value_processing_method)))
     LEFT JOIN eenheid_type ON ((eenheid_type.eenh_id = norm_value.lowerbound_uom_id)))
     LEFT JOIN compartiment_type ON ((compartiment_type.cptm_id = norm_value.cptm_id)))
     LEFT JOIN classification_type ON ((classification_type.cls_id = norm_value.norm_klasse_id)))
     LEFT JOIN bepaling_grens_type ON ((bepaling_grens_type.bpg_id = norm_value.lowerbound_limit_symbol_id)))
     LEFT JOIN bepaling_grens_type bgt ON ((bgt.bpg_id = norm_value.upperbound_limit_symbol_id)))
     LEFT JOIN namespace_type ON ((namespace_type.ns_id = vw_waterlichamen.waterbeheerder_code)))
     JOIN competentauthority_namespacetype ON ((competentauthority_namespacetype.ns_id = vw_waterlichamen.waterbeheerder_code)))
     JOIN vw_competent_authority ON ((vw_competent_authority."DB_ID" = competentauthority_namespacetype.ore_id)))
     LEFT JOIN ( SELECT substance_group_element.chs_id,
            substance_group_element.ssge_id
           FROM substance_group_element
          WHERE (substance_group_element.ssge_id = 3125)) ssg_3125 ON ((ssg_3125.chs_id = vw_waargenomen_eigenschap_db_id."ChemischeStof_DB_ID")))
     LEFT JOIN vw_krw_kwaliteitselement krw_kwal ON ((((krw_kwal."Watertype_Code")::text = (vw_oppervlaktewaterlichamen.referentietype)::text) AND (krw_kwal."Waargenomen_Eigenschap_DB_ID" = vw_waargenomen_eigenschap_db_id."DB_ID"))))
  WHERE ((level_of_area_type.loa_id = 5) AND (norm_groep_type.nmgp_id = 7) AND ((norm_value.end_lifespan_version IS NULL) OR (norm_value.end_lifespan_version >= now())))
  ORDER BY norm_value.nrmv_id, vw_waargenomen_eigenschap_db_id."DB_ID", classification_type.description, norm.last_change_time DESC, norm.wkrv_id DESC;


--
-- Name: vw_download_meetlocaties_krm; Type: VIEW; Schema: public; Owner: -
--

CREATE VIEW vw_download_meetlocaties_krm AS
 SELECT mo.geometry_etrs89 AS geometry,
    geometrytype(mo.geometry) AS geotype,
    mo.inspire_id_local_id AS mpnident,
    mo.name AS mpnomsch,
    mo.inspire_id_namespace_id AS wbhcode,
    mo.begin_lifespan_version AS startdatum,
    mo.end_lifespan_version AS einddatum,
    mo.additional_description AS memo,
    oe.naam AS externbron,
    mooi.hydro_id_local_id AS externcode,
    nf.emn_id AS meetnetid,
    nf.linking_time_begin AS meetnetstart,
    nf.linking_time_end AS meetnetend,
    mo.mno_id
   FROM (((((monitoring_object mo
     JOIN monitoring_feature mf ON ((mo.mno_id = mf.mnf_id)))
     JOIN environmental_monitoring_facility emf ON ((mo.mno_id = emf.emf_id)))
     JOIN network_facility nf ON ((nf.emf_id = emf.emf_id)))
     LEFT JOIN monitoring_object_other_ids mooi ON ((mooi.mno_id = mo.mno_id)))
     LEFT JOIN organisatorische_eenheid oe ON ((oe.ore_id = mooi.hydro_id_ore_id)));


--
-- Name: vw_ef_inspire; Type: VIEW; Schema: public; Owner: -
--

CREATE VIEW vw_ef_inspire AS
 SELECT ((((('NL.WBHCODE.'::text || monitoring_object.inspire_id_namespace_id) || '.'::text) || (monitoring_object.inspire_id_local_id)::text) || '.'::text) || monitoring_object.wkrv_id) AS inspireid,
        CASE
            WHEN (monitoring_object.additional_description IS NULL) THEN 'UNPOPULATED'::text
            ELSE NULL::text
        END AS additionaldescription_nilreason,
    monitoring_object.additional_description AS additionaldescription,
    monitoring_object.geometry_etrs89 AS st_transform,
    ('NL.WBHCODE.'::text || (namespace_type.code)::text) AS inspireid_namespace,
    monitoring_object.inspire_id_local_id AS inspireid_localid,
    monitoring_object.wkrv_id AS inspireid_version,
    'http://inspire.ec.europa.eu/codelist/MediaTypeValue/water'::text AS mediamonitored,
    monitoring_object.name,
    'http://inspire.ec.europa.eu/codelist/PurposeOfCollectionValue/waterKwaliteit'::text AS purpose,
    namespace_type.descrption AS responsibleparty_organisationname,
    'http://inspire.ec.europa.eu/codelist/RelatedPartyRoleValue/authority'::text AS responsibleparty_role,
    ('http://inspire.ec.europa.eu/codelist/PurposeOfCollectionValue/'::text || (measurement_regime_type.description)::text) AS measurementregime,
    'false'::text AS mobile,
    ('http://inspire.ec.europa.eu/codelist/ResultNatureValue/'::text || (result_acquisition_source_type.description)::text) AS resultacquisitionsource,
    ('http://inspire.ec.europa.eu/codelist/SpecialisedEMFTypeValue/'::text || (specialised_emf_type.description)::text) AS specialisedemftype
   FROM ((((((monitoring_object
     JOIN environmental_monitoring_facility ON ((monitoring_object.mno_id = environmental_monitoring_facility.emf_id)))
     JOIN monitoring_feature ON ((environmental_monitoring_facility.emf_id = monitoring_feature.mnf_id)))
     JOIN namespace_type ON ((namespace_type.ns_id = monitoring_object.inspire_id_namespace_id)))
     LEFT JOIN specialised_emf_type ON ((environmental_monitoring_facility.speciallised_emf_type_id = specialised_emf_type.semf_id)))
     LEFT JOIN result_acquisition_source_type ON ((environmental_monitoring_facility.result_acquisition_source_id = result_acquisition_source_type.ras_id)))
     LEFT JOIN measurement_regime_type ON ((environmental_monitoring_facility.measurement_regime_id = measurement_regime_type.mmr_id)))
  WHERE (monitoring_object.wkrv_id = 7);


--
-- Name: vw_grondwaterlichaam_kaart_bb; Type: VIEW; Schema: public; Owner: -
--

CREATE VIEW vw_grondwaterlichaam_kaart_bb AS
 SELECT gwb.gwb_id AS db_id,
    hydro_object.inspire_id_local_id AS gwbident,
    st_extent(mrz.geometry) AS extent,
    hydro_object.wkrv_id AS versie
   FROM ((ground_water_body gwb
     LEFT JOIN hydro_object ON ((gwb.gwb_id = hydro_object.hdo_id)))
     LEFT JOIN management_regulation_or_restriction_zone mrz ON ((gwb.gwb_id = mrz.mrz_id)))
  GROUP BY gwb.gwb_id, hydro_object.inspire_id_local_id, hydro_object.wkrv_id
  ORDER BY hydro_object.inspire_id_local_id, hydro_object.wkrv_id;


--
-- Name: vw_grondwaterlichamen_g; Type: VIEW; Schema: public; Owner: -
--

CREATE VIEW vw_grondwaterlichamen_g AS
 SELECT hydro_object.hdo_id AS db_id,
    hydro_object.inspire_id_local_id AS identificatie,
    hydro_object.inspire_id_namespace AS waterbeheerder_code,
    water_body.is_article_7 AS drinkwateronttrekking_jn,
    hdo_names.name AS omschrijving,
    management_regulation_or_restriction_zone.geometry,
    hdo_rbd.inspire_id_local_id AS stroomgebieddistrict,
    hydro_object.wkrv_id AS versie,
    ground_water_body.is_out_of_rbd AS is_buiten_deelstroomgebied,
    ground_water_body.is_transboundary AS is_grensoverschrijdend,
    ground_water_body.geological_formation_id,
    ground_water_body.vertical_orientation_id,
    ground_water_body.horizon_id AS horizon,
    substrate_type.omschrijving AS substraat,
    ground_water_body.is_layered AS is_gelaagd,
    ground_water_body.is_linked_to_terrestrial_ecosystems AS heeft_link_terrestrische_ecosystemen
   FROM (((((((management_regulation_or_restriction_zone
     JOIN hydro_object ON ((management_regulation_or_restriction_zone.mrz_id = hydro_object.hdo_id)))
     LEFT JOIN hdo_names ON ((hdo_names.hdo_id = management_regulation_or_restriction_zone.mrz_id)))
     JOIN water_body ON ((water_body.wbd_id = management_regulation_or_restriction_zone.mrz_id)))
     JOIN ground_water_body ON ((ground_water_body.gwb_id = management_regulation_or_restriction_zone.mrz_id)))
     JOIN river_basin_disrict rbd ON ((rbd.rbd_id = water_body.rbd_id)))
     JOIN hydro_object hdo_rbd ON ((rbd.rbd_id = hdo_rbd.hdo_id)))
     JOIN substrate_type ON ((substrate_type.sub_id = ground_water_body.substrate_id)))
  WHERE ((management_regulation_or_restriction_zone.mrz_type)::text = 'GroundWaterBody'::text);


--
-- Name: vw_grondwaterlichamen_shape; Type: VIEW; Schema: public; Owner: -
--

CREATE VIEW vw_grondwaterlichamen_shape AS
 SELECT hydro_object.hdo_id AS db_id,
    hydro_object.inspire_id_local_id AS gwbident,
    hydro_object.inspire_id_namespace AS namespac,
    vw_competent_authority."Omschrijving" AS wbhcode,
    water_body.is_article_7 AS gwbcons,
    hdo_names.name AS gwbnaam,
    management_regulation_or_restriction_zone.geometry,
    hdo2.inspire_id_local_id AS sgbident,
    water_body.level_of_detail AS schaal,
    ground_water_body.area AS oppvte,
    ground_water_body.is_transboundary AS grensovs,
    ground_water_body.average_depth_value AS gemdiepte,
    ground_water_body.average_thickness_value AS gemdikte,
    ground_water_body.capacity_value AS volme,
    ground_water_body.horizon_id AS gwbhoriz,
    ground_water_body.is_layered AS gelaagd,
    ground_water_body.is_linked_to_terrestrial_ecosystems AS gwb_ter,
    management_regulation_or_restriction_zone.begin_designation AS geldig_b,
    management_regulation_or_restriction_zone.end_designation AS geldig_e,
    geological_formation_type.code AS gwbaquif,
    gw_vertical_orientation_type.code AS gwbverto
   FROM (((((((((((hydro_object
     LEFT JOIN hdo_names ON ((hdo_names.hdo_id = hydro_object.hdo_id)))
     JOIN wkr_version ON ((wkr_version.wkrv_id = hydro_object.wkrv_id)))
     LEFT JOIN management_regulation_or_restriction_zone ON ((management_regulation_or_restriction_zone.mrz_id = hydro_object.hdo_id)))
     LEFT JOIN water_body ON ((water_body.wbd_id = hydro_object.hdo_id)))
     JOIN hydro_object hdo2 ON ((hdo2.hdo_id = water_body.rbd_id)))
     LEFT JOIN ground_water_body ON ((ground_water_body.gwb_id = hydro_object.hdo_id)))
     JOIN substrate_type ON ((substrate_type.sub_id = ground_water_body.substrate_id)))
     LEFT JOIN competentauthority_namespacetype ON ((competentauthority_namespacetype.ns_id = hydro_object.inspire_id_namespace)))
     LEFT JOIN vw_competent_authority ON ((vw_competent_authority."DB_ID" = competentauthority_namespacetype.ore_id)))
     LEFT JOIN geological_formation_type ON ((geological_formation_type.gfm_id = ground_water_body.geological_formation_id)))
     LEFT JOIN gw_vertical_orientation_type ON ((gw_vertical_orientation_type.gvo_id = ground_water_body.vertical_orientation_id)))
  ORDER BY hydro_object.inspire_id_local_id, wkr_version.wkrv_id DESC;


--
-- Name: vw_gw_onttrekking; Type: VIEW; Schema: public; Owner: -
--

CREATE VIEW vw_gw_onttrekking AS
 SELECT hydro_object.hdo_id AS "DB_ID",
    hydro_object.inspire_id_local_id AS "Identificatie",
    hdo_names.name AS omschrijving,
    gw_abstraction_point.company AS bedrijf,
    gw_abstraction_point.rewab_code AS "REWAB_Code",
    rewab_type.description AS "REWAB_Type",
    wkr_version.wkrv_id AS wkr_versie,
    wkr_version.begin_lifespan_version AS wkr_beginversie,
    wkr_version.end_lifespan_version AS wkr_eindversie
   FROM (((((hydro_object
     LEFT JOIN hdo_names ON ((hdo_names.hdo_id = hydro_object.hdo_id)))
     JOIN abstraction_point ON ((hydro_object.hdo_id = abstraction_point.asp_id)))
     JOIN gw_abstraction_point ON ((hydro_object.hdo_id = gw_abstraction_point.gasp_id)))
     JOIN rewab_type ON ((rewab_type.rwb_id = gw_abstraction_point.rewab_id)))
     JOIN wkr_version ON ((wkr_version.wkrv_id = hydro_object.wkrv_id)));


--
-- Name: vw_gw_onttrekking_csv; Type: VIEW; Schema: public; Owner: -
--

CREATE VIEW vw_gw_onttrekking_csv AS
 SELECT namespace_type.code AS "Namespace",
    hydro_object.inspire_id_local_id AS "LokaalID",
    hdo_names.name AS "Omschrijving",
    gw_abstraction_point.company AS "Bedrijf",
    rewab_type.description AS "Onttrekking.Type",
    st_x((st_astext((st_dump(abstraction_point.geometry)).geom))::geometry) AS "RD_X",
    st_y((st_astext((st_dump(abstraction_point.geometry)).geom))::geometry) AS "RD_Y",
    hdo.inspire_id_local_id AS "Grondwaterlichaam.Identificatie",
    hdo.wkrv_id AS "Versie"
   FROM ((((((hydro_object
     LEFT JOIN hdo_names ON ((hdo_names.hdo_id = hydro_object.hdo_id)))
     JOIN abstraction_point ON ((hydro_object.hdo_id = abstraction_point.asp_id)))
     JOIN gw_abstraction_point ON ((hydro_object.hdo_id = gw_abstraction_point.gasp_id)))
     JOIN rewab_type ON ((rewab_type.rwb_id = gw_abstraction_point.rewab_id)))
     JOIN namespace_type ON ((namespace_type.ns_id = hydro_object.inspire_id_namespace)))
     JOIN hydro_object hdo ON ((hdo.hdo_id = abstraction_point.wbd_id)))
  ORDER BY namespace_type.code, hdo.inspire_id_local_id;


--
-- Name: vw_gw_onttrekking_g_buffer; Type: VIEW; Schema: public; Owner: -
--

CREATE VIEW vw_gw_onttrekking_g_buffer AS
 SELECT t."DB_ID",
    t."Identificatie",
    t.omschrijving,
    t.geometry,
    t.bedrijf,
    t."REWAB_DB_ID",
    t."REWAB_Code",
    t."REWAB_Type",
    t.wkr_versie,
    t."Stroomgebieddistrict",
    t.distance
   FROM ( SELECT p."DB_ID",
            p."Identificatie",
            p.omschrijving,
            p.geometry,
            p.bedrijf,
            p."REWAB_DB_ID",
            p."REWAB_Code",
            p."REWAB_Type",
            p.wkr_versie,
            p."Stroomgebieddistrict",
            st_distance(p.geometry, ( SELECT vw_oppervlaktewaterlichaam_l_kaart.geometry
                   FROM vw_oppervlaktewaterlichaam_l_kaart
                  WHERE ((upper((vw_oppervlaktewaterlichaam_l_kaart.owmident)::text) = upper('NL95_3A'::text)) AND (vw_oppervlaktewaterlichaam_l_kaart.versie = 11)))) AS distance
           FROM vw_gw_onttrekking_g p
        UNION ALL
         SELECT p."DB_ID",
            p."Identificatie",
            p.omschrijving,
            p.geometry,
            p.bedrijf,
            p."REWAB_DB_ID",
            p."REWAB_Code",
            p."REWAB_Type",
            p.wkr_versie,
            p."Stroomgebieddistrict",
            st_distance(p.geometry, ( SELECT vw_oppervlaktewaterlichaam_v_kaart.geometry
                   FROM vw_oppervlaktewaterlichaam_v_kaart
                  WHERE ((upper((vw_oppervlaktewaterlichaam_v_kaart.owmident)::text) = upper('NL95_3A'::text)) AND (vw_oppervlaktewaterlichaam_v_kaart.versie = 11)))) AS distance
           FROM vw_gw_onttrekking_g p) t;


--
-- Name: vw_gw_onttrekking_g_punt; Type: VIEW; Schema: public; Owner: -
--

CREATE VIEW vw_gw_onttrekking_g_punt AS
 SELECT hydro_object.hdo_id AS "DB_ID",
    hydro_object.inspire_id_local_id AS "Identificatie",
    hdo_names.name AS omschrijving,
    abstraction_point.geometry,
    gw_abstraction_point.company AS bedrijf,
    rewab_type.rwb_id AS "REWAB_DB_ID",
    gw_abstraction_point.rewab_code AS "REWAB_Code",
    rewab_type.description AS "REWAB_Type",
    hydro_object.wkrv_id AS wkr_versie
   FROM ((((hydro_object
     LEFT JOIN hdo_names ON ((hdo_names.hdo_id = hydro_object.hdo_id)))
     JOIN abstraction_point ON ((hydro_object.hdo_id = abstraction_point.asp_id)))
     JOIN gw_abstraction_point ON ((hydro_object.hdo_id = gw_abstraction_point.gasp_id)))
     JOIN rewab_type ON ((rewab_type.rwb_id = gw_abstraction_point.rewab_id)))
  WHERE (geometrytype(abstraction_point.geometry) = 'MULTIPOINT'::text);


--
-- Name: vw_gw_onttrekking_shape; Type: VIEW; Schema: public; Owner: -
--

CREATE VIEW vw_gw_onttrekking_shape AS
 SELECT DISTINCT ON (hydro_object.inspire_id_local_id) hydro_object.inspire_id_local_id AS "IDENT",
    hdo_names.name AS "NAAM",
    abstraction_point.geometry,
    gw_abstraction_point.company AS "BEDRIJF",
    gw_abstraction_point.rewab_code AS "REWABCOD",
    rewab_type.description AS "REWABSRT"
   FROM (((((hydro_object
     LEFT JOIN hdo_names ON ((hdo_names.hdo_id = hydro_object.hdo_id)))
     JOIN abstraction_point ON ((hydro_object.hdo_id = abstraction_point.asp_id)))
     JOIN gw_abstraction_point ON ((hydro_object.hdo_id = gw_abstraction_point.gasp_id)))
     JOIN rewab_type ON ((rewab_type.rwb_id = gw_abstraction_point.rewab_id)))
     JOIN wkr_version ON ((wkr_version.wkrv_id = hydro_object.wkrv_id)))
  ORDER BY hydro_object.inspire_id_local_id, wkr_version.wkrv_id DESC;


--
-- Name: vw_gwl_owm_relatie; Type: VIEW; Schema: public; Owner: -
--

CREATE VIEW vw_gwl_owm_relatie AS
 SELECT relation_gwb_swb.gwsw_id AS "DB_ID",
    hdo_gwb.hdo_id AS "Grondwaterlichaam_DB_ID",
    hdo_gwb.inspire_id_local_id AS "Grondwaterlichaam_Identificatie",
    hdon_gwb.name AS "Grondwaterlichaam_Omschrijving",
    hdo_gwb.wkrv_id AS "Grondwaterlichaam_Versie",
    hdo_swb.hdo_id AS "Oppervlaktewaterlichaam_DB_ID",
    hdo_swb.inspire_id_local_id AS "OppervlakteWaterlichaam_Identificatie",
    hdon_swb.name AS "OppervlakteWaterlichaam_Omschrijving",
    hdo_gwb.wkrv_id AS "OppervlakteWaterlichaam_Versie",
    relation_type.rlt_id AS "RelatieType_DB_ID",
    relation_type.description AS "RelatieType"
   FROM (((((relation_gwb_swb
     JOIN relation_type ON ((relation_type.rlt_id = relation_gwb_swb.relation_type_id)))
     LEFT JOIN hydro_object hdo_swb ON ((hdo_swb.hdo_id = relation_gwb_swb.swb_id)))
     LEFT JOIN hdo_names hdon_swb ON ((hdo_swb.hdo_id = hdon_swb.hdo_id)))
     LEFT JOIN hydro_object hdo_gwb ON ((hdo_gwb.hdo_id = relation_gwb_swb.gwb_id)))
     LEFT JOIN hdo_names hdon_gwb ON ((hdo_gwb.hdo_id = hdon_gwb.hdo_id)))
  ORDER BY hdo_gwb.inspire_id_local_id, hdo_swb.inspire_id_local_id;


--
-- Name: vw_hydro_object_relaties; Type: VIEW; Schema: public; Owner: -
--

CREATE VIEW vw_hydro_object_relaties AS
 SELECT hdo_f.hdo_id AS db_id_bron,
    hdo_f.inspire_id_namespace AS namespace_bron,
    hdo_f.inspire_id_local_id AS identificatie_bron,
    hdo_f.hydro_object_type AS type_bron,
    hdo_f.wkrv_id AS versie_bron,
    rel_role_type.rrt_id AS db_id_rol,
    rel_role_type.description AS rol_omschrijving,
    related_hydro_object.comment AS rol_toelichting,
    hdo_t.hdo_id AS db_id_doel,
    hdo_t.inspire_id_namespace AS namespace_doel,
    hdo_t.inspire_id_local_id AS identificatie_doel,
    hdo_t.hydro_object_type AS type_doel,
    hdo_t.wkrv_id AS versie_doel
   FROM (((related_hydro_object
     LEFT JOIN rel_role_type ON ((rel_role_type.rrt_id = related_hydro_object.rrt_id)))
     LEFT JOIN hydro_object hdo_f ON ((hdo_f.hdo_id = related_hydro_object.from_hdo)))
     LEFT JOIN hydro_object hdo_t ON ((hdo_t.hdo_id = related_hydro_object.to_hdo)))
  ORDER BY hdo_f.hdo_id, hdo_f.wkrv_id, rel_role_type.rrt_id;


--
-- Name: vw_hydro_object_was_wordt_versies_geometrisch; Type: VIEW; Schema: public; Owner: -
--

CREATE VIEW vw_hydro_object_was_wordt_versies_geometrisch AS
 SELECT hdo_2.inspire_id_local_id AS identificatie_v2,
    hdo_2.hdo_id AS db_id_v2,
    hdo_3.inspire_id_local_id AS identificatie_v3,
    hdo_3.hdo_id AS db_id_v3,
    hdo_6.inspire_id_local_id AS identificatie_v6,
    hdo_6.hdo_id AS db_id_v6,
    hdo_4.inspire_id_local_id AS identificatie_v4,
    hdo_4.hdo_id AS db_id_v4
   FROM ((((((hydro_object hdo_4
     LEFT JOIN related_hydro_object rho_4 ON ((rho_4.from_hdo = hdo_4.hdo_id)))
     LEFT JOIN hydro_object hdo_6 ON ((rho_4.to_hdo = hdo_6.hdo_id)))
     LEFT JOIN related_hydro_object rho_6 ON ((rho_6.from_hdo = hdo_6.hdo_id)))
     LEFT JOIN hydro_object hdo_3 ON ((rho_6.to_hdo = hdo_3.hdo_id)))
     LEFT JOIN related_hydro_object rho_3 ON ((rho_3.from_hdo = hdo_3.hdo_id)))
     LEFT JOIN hydro_object hdo_2 ON ((rho_3.to_hdo = hdo_2.hdo_id)))
  WHERE (((hdo_4.hydro_object_type)::text = ANY (ARRAY[('GroundWaterBody'::character varying)::text, ('SurfaceWaterBody'::character varying)::text])) AND (hdo_4.wkrv_id = 4) AND (rho_4.rrt_id = 1) AND (rho_6.rrt_id = 1) AND (rho_3.rrt_id = 1))
  ORDER BY hdo_2.inspire_id_local_id;


--
-- Name: vw_hydro_object_was_wordt_versies_geometrisch_v11; Type: VIEW; Schema: public; Owner: -
--

CREATE VIEW vw_hydro_object_was_wordt_versies_geometrisch_v11 AS
 SELECT hdo_2.inspire_id_local_id AS identificatie_v2,
    hdo_2.hdo_id AS db_id_v2,
    hdo_3.inspire_id_local_id AS identificatie_v3,
    hdo_3.hdo_id AS db_id_v3,
    hdo_4.inspire_id_local_id AS identificatie_v4,
    hdo_4.hdo_id AS db_id_v4,
    hdo_8.inspire_id_local_id AS identificatie_v8,
    hdo_8.hdo_id AS db_id_v8,
    hdo_11.inspire_id_local_id AS identificatie_v11,
    hdo_11.hdo_id AS db_id_v11
   FROM ((((((((hydro_object hdo_11
     LEFT JOIN related_hydro_object rho_11 ON ((rho_11.from_hdo = hdo_11.hdo_id)))
     LEFT JOIN hydro_object hdo_8 ON ((rho_11.to_hdo = hdo_8.hdo_id)))
     LEFT JOIN related_hydro_object rho_8 ON ((rho_8.from_hdo = hdo_8.hdo_id)))
     LEFT JOIN hydro_object hdo_4 ON ((rho_8.to_hdo = hdo_4.hdo_id)))
     LEFT JOIN related_hydro_object rho_4 ON ((rho_4.from_hdo = hdo_4.hdo_id)))
     LEFT JOIN hydro_object hdo_3 ON ((rho_4.to_hdo = hdo_3.hdo_id)))
     LEFT JOIN related_hydro_object rho_3 ON ((rho_3.from_hdo = hdo_3.hdo_id)))
     LEFT JOIN hydro_object hdo_2 ON ((rho_3.to_hdo = hdo_2.hdo_id)))
  WHERE (((hdo_11.hydro_object_type)::text = ANY (ARRAY[('GroundWaterBody'::character varying)::text, ('SurfaceWaterBody'::character varying)::text])) AND (hdo_11.wkrv_id = 11) AND (rho_11.rrt_id = 1) AND (rho_8.rrt_id = 1) AND (rho_4.rrt_id = 1) AND (rho_3.rrt_id = 1))
  ORDER BY hdo_2.inspire_id_local_id;


--
-- Name: vw_krw_kwaliteitselement_gw; Type: VIEW; Schema: public; Owner: -
--

CREATE VIEW vw_krw_kwaliteitselement_gw AS
 SELECT wfd_qe_gwtype.qegw_id AS "DB_ID",
    vw_waargenomen_eigenschap."DB_ID" AS "Waargenomen_Eigenschap_DB_ID",
    wfd_qe_gwtype.name AS "Kwaliteitselement_Naam",
    wfd_qe_gwtype.sortorder,
    vw_waargenomen_eigenschap."Tpering_Code",
    vw_waargenomen_eigenschap."Typering_Omschrijving",
    vw_waargenomen_eigenschap."Grootheid_Code",
    vw_waargenomen_eigenschap."Grootheid_Omschrijving",
    vw_waargenomen_eigenschap."ChemischeStof_code",
    vw_waargenomen_eigenschap."ChemischeStof_Omschrijving",
    vw_waargenomen_eigenschap."ChemischeStof_CASnr",
    vw_waargenomen_eigenschap."Hoedanigheid_Code",
    vw_waargenomen_eigenschap."Hoedanigheid_Omschrijving",
    we2."DB_ID" AS "Onderdeel_van_EU_Typering_DB_ID",
    we2."Tpering_Code" AS "Onderdeel_van_EU_Typering_Code",
    we2."Typering_Omschrijving" AS "Onderdeel_van_EU_Typering_Omschrijving",
    we3."DB_ID" AS "Onderdeel_van_NL_Typering_DB_ID",
    we3."Tpering_Code" AS "Onderdeel_van_NL_Typering_Code",
    we3."Typering_Omschrijving" AS "Onderdeel_van_NL_Typering_Omschrijving",
    wfd_qe_gwtype.main_group AS "Is_hoofdgroep",
    wfd_qe_gwtype.is_applicable AS "Is_van_toepassing",
    wfd_qe_gwtype.is_excemption AS "Is_artikel_4",
    wfd_qe_gwtype.is_trendsubstance AS "Is_trend_stof",
    wfd_qe_gwtype.is_backgroundlevelsubstance AS "Is_drempelwaarde_stof",
    wfd_qe_gwtype.clsg_id AS "ClassifciatieGroep_DB_ID",
    classification_group_type.description AS "ClassificatieGroep_Omschrijving"
   FROM ((((wfd_qe_gwtype
     LEFT JOIN vw_waargenomen_eigenschap ON ((vw_waargenomen_eigenschap."DB_ID" = wfd_qe_gwtype.opt_id)))
     LEFT JOIN vw_waargenomen_eigenschap we2 ON ((we2."DB_ID" = wfd_qe_gwtype.part_of_opt_id_eu)))
     LEFT JOIN vw_waargenomen_eigenschap we3 ON ((we3."DB_ID" = wfd_qe_gwtype.part_of_opt_id_nl)))
     LEFT JOIN classification_group_type ON ((wfd_qe_gwtype.clsg_id = classification_group_type.clsg_id)))
  ORDER BY vw_waargenomen_eigenschap."Tpering_Code", vw_waargenomen_eigenschap."Grootheid_Code", vw_waargenomen_eigenschap."ChemischeStof_code";


--
-- Name: vw_lew2015_meetpunten; Type: VIEW; Schema: public; Owner: -
--

CREATE VIEW vw_lew2015_meetpunten AS
 SELECT monitoring_object.mno_id AS meetpunt_identificatie_db_id,
    monitoring_object.inspire_id_local_id AS "Meetpunt.identificatie",
    monitoring_object.name AS "Meetpunt.omschrijving",
    namespace_type.code AS "Waterbeheerder.code",
    namespace_type.descrption AS "Waterbeheerder.omschrijving",
    st_x(st_transform(monitoring_object.geometry, 28992)) AS "GeometriePunt.X_RD",
    st_y(st_transform(monitoring_object.geometry, 28992)) AS "GeometriePunt.Y_RD",
    monitoring_object.wkrv_id AS "Versie",
    monitoring_object.last_change_time
   FROM (((monitoring_object
     JOIN monitored_compartiment ON ((monitored_compartiment.mno_id = monitoring_object.mno_id)))
     JOIN namespace_type ON ((namespace_type.ns_id = monitoring_object.inspire_id_namespace_id)))
     JOIN monitoring_feature ON ((monitoring_feature.mnf_id = monitoring_object.mno_id)))
  WHERE (st_geometrytype(monitoring_object.geometry) = 'ST_Point'::text);


--
-- Name: VIEW vw_lew2015_meetpunten; Type: COMMENT; Schema: public; Owner: -
--

COMMENT ON VIEW vw_lew2015_meetpunten IS 'Overzicht van de meetpunten van waterbeheerders,';


--
-- Name: vw_lew2015_monsters_meetwaarden; Type: VIEW; Schema: public; Owner: -
--

CREATE VIEW vw_lew2015_monsters_meetwaarden AS
 SELECT nst.descrption AS "Waterbeheerder.omschrijving",
    mno.wkrv_id AS "Versie",
    mno.inspire_id_local_id AS "Meetpunt.identificatie",
    mno.inspire_id_namespace_id AS "Waterbeheerder.code",
    mno.name AS "Meetpunt.omschrijving",
    obs.obs_id AS "Observation.id",
    obs.phenomenon_time_begin AS "Observation.begindatum",
    obs.result_time AS "Observation.resultaatdatum",
    obs.last_change_time AS "Tijdstip.geladeninwkp",
    obs.observed_property_type AS "Observedpropertytype.id",
        CASE
            WHEN (opt.taxa_group_id IS NOT NULL) THEN 'Biotaxon'::text
            WHEN (opt.substance_group_id IS NOT NULL) THEN 'ChemischeStof'::text
            WHEN (opt.object_group_id IS NOT NULL) THEN 'Object'::text
            ELSE NULL::text
        END AS "Stof.soort",
        CASE
            WHEN (opt.taxa_group_id IS NOT NULL) THEN txg.name
            WHEN (opt.substance_group_id IS NOT NULL) THEN ssg.name
            WHEN (opt.object_group_id IS NOT NULL) THEN ojg.name
            ELSE NULL::character varying
        END AS "Stof.naam",
    hdh.code AS "Hoedanigheid.code",
    hdh.omschrijving AS "Hoedanigheid.omschrijving",
    grh.code AS "Grootheid.code",
    grh.omschrijving AS "Grootheid.omschrijving",
    eenh.eenh_id AS "Eenheid.id",
    eenh.code AS "Eenheid.code",
    eenh.omschrijving AS "Eenheid.omschrijving",
    obs.limit_symbol_id AS "Limietsymbool.id",
    bpg.omschrijving AS "Limietsymbool.omschrijving",
    obs.numeric_value AS "Numeriekewaarde",
    smpl.smpl_id AS "Monster.id",
    smpl.name AS "Monster.naam",
    smpl.sampling_location AS "Monster.locatie",
    smpl.material_class_id AS "Compartiment.id",
    cptm.code AS "Compartiment.code",
    cptm.description AS "Compartiment.omschrijving"
   FROM (((((((((((((((observation obs
     JOIN observed_property_type opt ON ((opt.opt_id = obs.observed_property_type)))
     JOIN eenheid_type eenh ON ((eenh.eenh_id = obs.numeric_value_uom_id)))
     JOIN observing_capability_observation ocbs ON ((ocbs.obs_id = obs.obs_id)))
     JOIN observing_capability osc ON ((osc.osc_id = ocbs.osc_id)))
     JOIN monitoring_object mno ON ((mno.mno_id = obs.mno_id)))
     JOIN namespace_type nst ON ((nst.ns_id = mno.inspire_id_namespace_id)))
     LEFT JOIN bepaling_grens_type bpg ON ((bpg.bpg_id = obs.limit_symbol_id)))
     LEFT JOIN observing_capability_sample ocsa ON ((ocsa.osc_id = osc.osc_id)))
     LEFT JOIN sample smpl ON ((smpl.smpl_id = ocsa.smpl_id)))
     LEFT JOIN hoedanigheid_type hdh ON ((hdh.hdh_id = opt.hoedanigheid_id)))
     LEFT JOIN grootheid_type grh ON ((grh.grh_id = opt.quantity_id)))
     LEFT JOIN taxa_group txg ON ((txg.txg_id = opt.taxa_group_id)))
     LEFT JOIN substance_group ssg ON ((ssg.ssg_id = opt.substance_group_id)))
     LEFT JOIN object_group ojg ON ((ojg.ojg_id = opt.object_group_id)))
     LEFT JOIN compartiment_type cptm ON ((cptm.cptm_id = smpl.material_class_id)));


--
-- Name: VIEW vw_lew2015_monsters_meetwaarden; Type: COMMENT; Schema: public; Owner: -
--

COMMENT ON VIEW vw_lew2015_monsters_meetwaarden IS 'Geeft een overzicht van de geladen meetwaarden met monsters per waterbeheerder en zijn meetpunten.';


--
-- Name: vw_lew2015_waterbeheerders; Type: VIEW; Schema: public; Owner: -
--

CREATE VIEW vw_lew2015_waterbeheerders AS
 SELECT namespace_type.code,
    namespace_type.descrption,
    competent_authority.namespace_id,
    competent_authority.legal_status,
    competent_authority.legal_status_reference,
    competent_authority.legal_status_summary,
    competentauthority_namespacetype.ca_ns_id,
    competentauthority_namespacetype.last_change_time,
    namespace_type.ns_id,
    organisatorische_eenheid.ore_id,
    organisatorische_eenheid.organisatie_identificatie,
    organisatorische_eenheid.naam,
    organisatorische_eenheid.naam_verkort
   FROM (((competentauthority_namespacetype
     JOIN competent_authority ON ((competentauthority_namespacetype.ore_id = competent_authority.ore_id)))
     JOIN namespace_type ON (((competentauthority_namespacetype.ns_id = namespace_type.ns_id) AND (competent_authority.namespace_id = namespace_type.ns_id))))
     JOIN organisatorische_eenheid ON ((competent_authority.ore_id = organisatorische_eenheid.ore_id)));


--
-- Name: VIEW vw_lew2015_waterbeheerders; Type: COMMENT; Schema: public; Owner: -
--

COMMENT ON VIEW vw_lew2015_waterbeheerders IS 'Geeft veel gegevens over de waterbeheerders.';


--
-- Name: vw_reportversion; Type: VIEW; Schema: public; Owner: -
--

CREATE VIEW vw_reportversion AS
 SELECT report_version.rpv_id AS db_id,
    object_state_type.decsription AS rapportagestatus,
    reporting_period.description AS rapportageperiode,
    reporting_period.period_start AS rapportageperiodebegin,
    reporting_period.period_end AS rapportageperiodeeind,
    legislation_reference_type.lgr_id AS rapportagebasis_id,
    legislation_reference_type.legal_name AS rapportagebasis_omschrijving,
    report_version.begin_lifespan_version AS beginrapportage,
    report_version.end_lifespan_version AS eindrapportage,
    report_version.is_public_data AS publiektoegankelijk,
    wkr_version.wkrv_id AS wkr_versie,
    wkr_version.begin_lifespan_version AS wkr_beginversie,
    wkr_version.end_lifespan_version AS wkr_eindversie
   FROM ((legislation_reference_type
     JOIN reporting_period ON ((legislation_reference_type.lgr_id = reporting_period.leg_ref_id)))
     FULL JOIN ((report_version
     JOIN object_state_type ON ((report_version.ost_id = object_state_type.ost_id)))
     FULL JOIN wkr_version ON ((report_version.wkrv_id = wkr_version.wkrv_id))) ON ((reporting_period.rpp_id = report_version.rpp_id)))
  ORDER BY report_version.rpv_id, reporting_period.period_start;


--
-- Name: vw_maatregelen; Type: VIEW; Schema: public; Owner: -
--

CREATE VIEW vw_maatregelen AS
 SELECT mm.mtm_id AS "DB_ID",
    samt.local_id AS "Identifcatie",
    samt.measure_name AS "Naam",
    samt.measure_description AS "Omschrijving",
    samt.comment AS "Toelichting",
    samt.associated_link_desc AS "Bron_Omschrijving",
    vwr.rapportageperiodebegin AS "Periode_Begindatum",
    vwr.rapportageperiodeeind AS "Periode_Einddatum",
    loat.description AS "Niveau",
    samteu.smeu_id,
    samteu.name AS "EUType_Omschrijving",
    samt.amount_value AS "Hoeveelheid",
    et.code AS "Eenheid_Code",
    et.omschrijving AS "Eenheid_Omschrijving",
    oe.organisatie_identificatie AS "Verantwoordelijke_Overheid",
    can.ns_id AS "Waterbeheerder_DB_ID",
    samt.initiative_party AS "Initiatiefnemer",
    oct.omschrijving AS "Initiatiefnemer_Categorie",
    vwsend."Identificatie" AS "Stroomgebied_Identificatie",
    samt.is_additional_measure AS "Opgenomen_In_SGBP"
   FROM ((((((((((monitored_measure mm
     JOIN supp_add_measure_type samt ON ((mm.mtm_id = samt.smnl_id)))
     JOIN sw_supp_measure_eu_type samteu ON ((samteu.smeu_id = samt.smeu_id)))
     JOIN eenheid_type et ON ((et.eenh_id = samteu.eenh_id)))
     JOIN organisation_category_type oct ON ((oct.ocat_id = samt.initiative_party_ocat_id)))
     JOIN vw_reportversion vwr ON ((vwr.db_id = mm.rpv_id)))
     JOIN level_of_area_type loat ON ((loat.loa_id = mm.level_of_measure_id)))
     JOIN river_basin_management_plan rbmp ON ((rbmp.rbmp_id = samt.rbmp_id)))
     JOIN vw_sg_en_dsg_districten vwsend ON ((vwsend."DB_ID" = rbmp.rbd_id)))
     JOIN competentauthority_namespacetype can ON ((can.ns_id = samt.namespace_id)))
     JOIN organisatorische_eenheid oe ON ((oe.ore_id = can.ore_id)));


--
-- Name: vw_maatregelen_csv; Type: VIEW; Schema: public; Owner: -
--

CREATE VIEW vw_maatregelen_csv AS
 SELECT maatregelen.mtm_id AS "DB_ID",
    rv2.rpp_id AS periodeid,
    ('NL'::text || (wb_nst.code)::text) AS "Namespace",
    regexp_replace((supp_add_measure_type.local_id)::text, '\r|\n'::text, ''::text, 'g'::text) AS "LokaalID",
    regexp_replace((supp_add_measure_type.measure_name)::text, '\r|\n'::text, ''::text, 'g'::text) AS "Naam",
    rpp.description AS "SGBPPeriode.Omschrijving",
    ((date_part('year'::text, reporting_period.period_start) || '-'::text) || date_part('year'::text, reporting_period.period_end)) AS "UitvoeringIn",
    regexp_replace((sw_supp_measure_eu_type.code)::text, '\r|\n'::text, ''::text, 'g'::text) AS "KRWmaatregel.Code",
    regexp_replace((supp_add_measure_type.measure_description)::text, '\r|\n'::text, ''::text, 'g'::text) AS "Toelichting",
    regexp_replace((level_of_area_type.code)::text, '\r|\n'::text, ''::text, 'g'::text) AS "KRWMaatregelNiveau.Code",
    array_to_string(ARRAY( SELECT DISTINCT regexp_replace((ho.inspire_id_local_id)::text, '\r|\n'::text, ''::text, 'g'::text) AS regexp_replace
           FROM (hydro_object ho
             JOIN measure_per_man_reg_or_restr_zone mz ON ((mz.mrz_id = ho.hdo_id)))
          WHERE (mz.mtm_id = maatregelen.mtm_id)), '|'::text) AS "HoortbijKRWwaterlichaam",
    stroomgebieddistrict.inspire_id_local_id AS "KRWstroomgebiedDistrict.Code",
    supp_add_measure_type.amount_value AS "OmvangNumeriekeWaarde",
    regexp_replace((eenheid_type.code)::text, '\r|\n'::text, ''::text, 'g'::text) AS omvangeenheidcode,
    supp_add_measure_type.is_additional_measure AS "OpnameInSGBPJN",
    regexp_replace((organisation_category_type.code)::text, '\r|\n'::text, ''::text, 'g'::text) AS "Initiatiefnemer.Code",
    regexp_replace(supp_add_measure_type.initiative_party, '\r|\n'::text, ''::text, 'g'::text) AS "Initiatiefnemer.Naam",
    array_to_string(ARRAY( SELECT DISTINCT regexp_replace((t.code)::text, '\r|\n'::text, ''::text, 'g'::text) AS regexp_replace
           FROM (monitored_measure_eu_fund m
             JOIN eu_fund_type t ON ((t.euf_id = m.euf_id)))
          WHERE (m.mtm_id = maatregelen.mtm_id)), '|'::text) AS "EUFonds.Code",
    array_to_string(ARRAY( SELECT DISTINCT regexp_replace((vbg."Identificatie")::text, '\r|\n'::text, ''::text, 'g'::text) AS regexp_replace
           FROM (vw_beschermdegebieden vbg
             JOIN measure_per_man_protected_area mpmpa ON ((mpmpa.wpa_id = vbg."DB_ID")))
          WHERE ((mpmpa.mtm_id = maatregelen.mtm_id) AND (vbg."Versie_ID" = rv2.wkrv_id))), '|'::text) AS "RelatieMetNatura2000Gebied",
    array_to_string(ARRAY( SELECT DISTINCT regexp_replace((vgo."Identificatie")::text, '\r|\n'::text, ''::text, 'g'::text) AS regexp_replace
           FROM (vw_gw_onttrekking vgo
             JOIN measure_per_abstraction_point mpap ON ((mpap.asp_id = vgo."DB_ID")))
          WHERE ((mpap.mtm_id = maatregelen.mtm_id) AND (vgo.wkr_versie = rv2.wkrv_id))), '|'::text) AS "RelatieMetWaterwinning",
    river_basin_management_plan.wkrv_id AS versie
   FROM ((((((((((((((monitored_measure maatregelen
     JOIN supp_add_measure_type ON ((supp_add_measure_type.smnl_id = maatregelen.mtm_id)))
     JOIN sw_supp_measure_eu_type ON ((sw_supp_measure_eu_type.smeu_id = supp_add_measure_type.smeu_id)))
     JOIN eenheid_type ON ((eenheid_type.eenh_id = sw_supp_measure_eu_type.eenh_id)))
     JOIN namespace_type wb_nst ON ((wb_nst.ns_id = supp_add_measure_type.namespace_id)))
     JOIN competentauthority_namespacetype ON ((competentauthority_namespacetype.ns_id = wb_nst.ns_id)))
     JOIN competent_authority ON ((competent_authority.ore_id = competentauthority_namespacetype.ore_id)))
     JOIN report_version ON ((report_version.rpv_id = maatregelen.rpv_id)))
     JOIN reporting_period ON ((reporting_period.rpp_id = report_version.rpp_id)))
     JOIN level_of_area_type ON ((level_of_area_type.loa_id = maatregelen.level_of_measure_id)))
     JOIN organisation_category_type ON ((organisation_category_type.ocat_id = supp_add_measure_type.initiative_party_ocat_id)))
     JOIN river_basin_management_plan ON ((river_basin_management_plan.rbmp_id = supp_add_measure_type.rbmp_id)))
     JOIN hydro_object stroomgebieddistrict ON ((stroomgebieddistrict.hdo_id = river_basin_management_plan.rbd_id)))
     JOIN report_version rv2 ON ((rv2.wkrv_id = river_basin_management_plan.wkrv_id)))
     JOIN reporting_period rpp ON ((rpp.rpp_id = rv2.rpp_id)))
  ORDER BY supp_add_measure_type.local_id;


--
-- Name: vw_maatregelen_csv_for_download; Type: VIEW; Schema: public; Owner: -
--

CREATE VIEW vw_maatregelen_csv_for_download AS
 SELECT DISTINCT dqw."DB_ID",
    dqw."Namespace",
    dqw."Waterbeheerder_Naam",
    dqw."LokaalID",
    dqw."Naam",
    dqw."SGBPPeriode_Omschrijving",
    dqw."UitvoeringIn",
    dqw."KRWmaatregel_Code",
    dqw."KRWmaatregel_Naam",
    dqw."Voortgang_Toelichting",
    dqw."Hoofdcategorie",
    dqw."Index",
    dqw."SGBP_Klasse",
    dqw."SGBP_Harmonisatie",
    dqw."SGBP_code",
    dqw."SGBP_artikel",
    dqw."SGBP_Hoofdcategorie",
    dqw."KRWMaatregelNiveau_Code",
    dqw."KRWMaatregelNiveau_Omschrijving",
    dqw."HoortbijKRWwaterlichaam",
    dqw."KRWstroomgebiedDistrict_Code",
    dqw."OpnameInSGBPJN",
    dqw."Initiatiefnemer_Code",
    dqw."Initiatiefnemer_Naam",
    dqw."EUFonds_Code",
    dqw."RelatieMetNatura2000Gebied",
    dqw."RelatieMetWaterwinning",
    dqw.versie,
    dqw."OmvangNumeriekeWaarde",
    dqw.omvangeenheidcode,
    dqw."Plan",
    dqw."Uitvoering",
    dqw."Uitgevoerd",
    dqw."Gefaseerd",
    dqw."Vervangen",
    dqw."Ingetrokken",
    dqw."Jaar_voortgang"
   FROM ( SELECT mtm.mtm_id AS "DB_ID",
            ('NL'::text || (wb_nst.code)::text) AS "Namespace",
            wb_nst.descrption AS "Waterbeheerder_Naam",
            regexp_replace((supp_add_measure_type.local_id)::text, '\r|\n'::text, ''::text, 'g'::text) AS "LokaalID",
            regexp_replace((supp_add_measure_type.measure_name)::text, '\r|\n'::text, ''::text, 'g'::text) AS "Naam",
            rpp.description AS "SGBPPeriode_Omschrijving",
            ((date_part('year'::text, reporting_period.period_start) || '-'::text) || date_part('year'::text, reporting_period.period_end)) AS "UitvoeringIn",
            regexp_replace((sw_supp_measure_eu_type.code)::text, '\r|\n'::text, ''::text, 'g'::text) AS "KRWmaatregel_Code",
            sw_supp_measure_eu_type.name AS "KRWmaatregel_Naam",
            regexp_replace((supp_add_measure_type.measure_description)::text, '\r|\n'::text, ''::text, 'g'::text) AS "Voortgang_Toelichting",
            sw_supp_measure_eu_type.hoofdcategorie AS "Hoofdcategorie",
            sw_supp_measure_eu_type.index AS "Index",
            sw_supp_measure_eu_type.klasse AS "SGBP_Klasse",
            sw_supp_measure_eu_type.harmonisatie AS "SGBP_Harmonisatie",
            sw_supp_measure_eu_type.code_sgbp AS "SGBP_code",
            sw_supp_measure_eu_type.artikel_sgbp AS "SGBP_artikel",
            sw_supp_measure_eu_type.tablkop_sgbp AS "SGBP_Hoofdcategorie",
            regexp_replace((level_of_area_type.code)::text, '\r|\n'::text, ''::text, 'g'::text) AS "KRWMaatregelNiveau_Code",
            regexp_replace((level_of_area_type.description)::text, '\r|\n'::text, ''::text, 'g'::text) AS "KRWMaatregelNiveau_Omschrijving",
            array_to_string(ARRAY( SELECT DISTINCT regexp_replace((ho.inspire_id_local_id)::text, '\r|\n'::text, ''::text, 'g'::text) AS regexp_replace
                   FROM (hydro_object ho
                     JOIN measure_per_man_reg_or_restr_zone mz ON ((mz.mrz_id = ho.hdo_id)))
                  WHERE (mz.mtm_id = mtm.mtm_id)), '|'::text) AS "HoortbijKRWwaterlichaam",
            stroomgebieddistrict.inspire_id_local_id AS "KRWstroomgebiedDistrict_Code",
            supp_add_measure_type.is_additional_measure AS "OpnameInSGBPJN",
            regexp_replace((organisation_category_type.code)::text, '\r|\n'::text, ''::text, 'g'::text) AS "Initiatiefnemer_Code",
            regexp_replace(supp_add_measure_type.initiative_party, '\r|\n'::text, ''::text, 'g'::text) AS "Initiatiefnemer_Naam",
            array_to_string(ARRAY( SELECT DISTINCT regexp_replace((t.code)::text, '\r|\n'::text, ''::text, 'g'::text) AS regexp_replace
                   FROM (monitored_measure_eu_fund m
                     JOIN eu_fund_type t ON ((t.euf_id = m.euf_id)))
                  WHERE (m.mtm_id = mtm.mtm_id)), '|'::text) AS "EUFonds_Code",
            array_to_string(ARRAY( SELECT DISTINCT regexp_replace((vbg."Identificatie")::text, '\r|\n'::text, ''::text, 'g'::text) AS regexp_replace
                   FROM (vw_beschermdegebieden vbg
                     JOIN measure_per_man_protected_area mpmpa ON ((mpmpa.wpa_id = vbg."DB_ID")))
                  WHERE ((mpmpa.mtm_id = mtm.mtm_id) AND (vbg."Versie_ID" = river_basin_management_plan.wkrv_id))), '|'::text) AS "RelatieMetNatura2000Gebied",
            array_to_string(ARRAY( SELECT DISTINCT regexp_replace((vgo."Identificatie")::text, '\r|\n'::text, ''::text, 'g'::text) AS regexp_replace
                   FROM (vw_gw_onttrekking vgo
                     JOIN measure_per_abstraction_point mpap ON ((mpap.asp_id = vgo."DB_ID")))
                  WHERE ((mpap.mtm_id = mtm.mtm_id) AND (vgo.wkr_versie = river_basin_management_plan.wkrv_id))), '|'::text) AS "RelatieMetWaterwinning",
            river_basin_management_plan.wkrv_id AS versie,
            (''::text || supp_add_measure_type.amount_value) AS "OmvangNumeriekeWaarde",
            regexp_replace((eenheid_type.code)::text, '\r|\n'::text, ''::text, 'g'::text) AS omvangeenheidcode,
            (''::text || mp1.amount_value) AS "Plan",
            (''::text || mp2.amount_value) AS "Uitvoering",
            (''::text || mp3.amount_value) AS "Uitgevoerd",
            (''::text || mp4.amount_value) AS "Gefaseerd",
            (''::text || mp5.amount_value) AS "Vervangen",
            (''::text || mp6.amount_value) AS "Ingetrokken",
            mp1.year AS "Jaar_voortgang",
            ca.ore_id AS waterbeheerderoreid
           FROM (((((((((((((((((((((((((competent_authority ca
             JOIN namespace_type nst ON ((ca.namespace_id = nst.ns_id)))
             JOIN competentauthority_namespacetype cans ON ((cans.ore_id = ca.ore_id)))
             JOIN hydro_object hdo ON ((cans.ns_id = hdo.inspire_id_namespace)))
             JOIN measure_per_man_reg_or_restr_zone mpmr ON ((hdo.hdo_id = mpmr.mrz_id)))
             JOIN monitored_measure mtm ON ((mpmr.mtm_id = mtm.mtm_id)))
             JOIN supp_add_measure_type ON ((supp_add_measure_type.smnl_id = mtm.mtm_id)))
             JOIN sw_supp_measure_eu_type ON ((sw_supp_measure_eu_type.smeu_id = supp_add_measure_type.smeu_id)))
             JOIN eenheid_type ON ((eenheid_type.eenh_id = sw_supp_measure_eu_type.eenh_id)))
             JOIN namespace_type wb_nst ON ((wb_nst.ns_id = supp_add_measure_type.namespace_id)))
             JOIN competentauthority_namespacetype ON ((competentauthority_namespacetype.ns_id = wb_nst.ns_id)))
             JOIN competent_authority ON ((competent_authority.ore_id = competentauthority_namespacetype.ore_id)))
             JOIN report_version ON ((report_version.rpv_id = mtm.rpv_id)))
             JOIN reporting_period ON ((reporting_period.rpp_id = report_version.rpp_id)))
             JOIN level_of_area_type ON ((level_of_area_type.loa_id = mtm.level_of_measure_id)))
             JOIN organisation_category_type ON ((organisation_category_type.ocat_id = supp_add_measure_type.initiative_party_ocat_id)))
             JOIN river_basin_management_plan ON ((river_basin_management_plan.rbmp_id = supp_add_measure_type.rbmp_id)))
             JOIN hydro_object stroomgebieddistrict ON ((stroomgebieddistrict.hdo_id = river_basin_management_plan.rbd_id)))
             JOIN report_version rv2 ON ((rv2.wkrv_id = river_basin_management_plan.wkrv_id)))
             JOIN reporting_period rpp ON (((rpp.rpp_id = rv2.rpp_id) AND (rv2.begin_lifespan_version <= now()) AND ((rv2.end_lifespan_version > now()) OR (rv2.end_lifespan_version IS NULL)) AND (rpp.leg_ref_id = 1))))
             LEFT JOIN measure_progress mp1 ON (((supp_add_measure_type.smnl_id = mp1.mtm_id) AND (mp1.mst_id = 1) AND (mp1.year = 2015))))
             LEFT JOIN measure_progress mp2 ON (((supp_add_measure_type.smnl_id = mp2.mtm_id) AND (mp2.mst_id = 2) AND (mp2.year = 2015))))
             LEFT JOIN measure_progress mp3 ON (((supp_add_measure_type.smnl_id = mp3.mtm_id) AND (mp3.mst_id = 3) AND (mp3.year = 2015))))
             LEFT JOIN measure_progress mp4 ON (((supp_add_measure_type.smnl_id = mp4.mtm_id) AND (mp4.mst_id = 4) AND (mp4.year = 2015))))
             LEFT JOIN measure_progress mp5 ON (((supp_add_measure_type.smnl_id = mp5.mtm_id) AND (mp5.mst_id = 5) AND (mp5.year = 2015))))
             LEFT JOIN measure_progress mp6 ON (((supp_add_measure_type.smnl_id = mp6.mtm_id) AND (mp6.mst_id = 6) AND (mp6.year = 2015))))
          GROUP BY mtm.mtm_id, wb_nst.code, wb_nst.descrption, supp_add_measure_type.local_id, supp_add_measure_type.measure_name, rpp.description, reporting_period.period_start, reporting_period.period_end, sw_supp_measure_eu_type.code, sw_supp_measure_eu_type.name, supp_add_measure_type.measure_description, sw_supp_measure_eu_type.hoofdcategorie, sw_supp_measure_eu_type.index, sw_supp_measure_eu_type.klasse, sw_supp_measure_eu_type.harmonisatie, sw_supp_measure_eu_type.code_sgbp, sw_supp_measure_eu_type.artikel_sgbp, sw_supp_measure_eu_type.tablkop_sgbp, level_of_area_type.code, level_of_area_type.description, stroomgebieddistrict.inspire_id_local_id, supp_add_measure_type.is_additional_measure, organisation_category_type.code, supp_add_measure_type.initiative_party, river_basin_management_plan.wkrv_id, supp_add_measure_type.amount_value, eenheid_type.code, mp1.amount_value, mp2.amount_value, mp3.amount_value, mp4.amount_value, mp5.amount_value, mp6.amount_value, mp1.year, ca.ore_id
          ORDER BY supp_add_measure_type.local_id) dqw;


--
-- Name: vw_maatregelen_dgrw_2011; Type: VIEW; Schema: public; Owner: -
--

CREATE VIEW vw_maatregelen_dgrw_2011 AS
 SELECT maatregelen.mtm_id AS "DB_ID",
    ('NL'::text || (wb_nst.code)::text) AS "Namespace",
    wb_nst.descrption AS "Waterbeheerder_Naam",
    regexp_replace((supp_add_measure_type.local_id)::text, '\r|\n'::text, ''::text, 'g'::text) AS "LokaalID",
    regexp_replace((supp_add_measure_type.measure_name)::text, '\r|\n'::text, ''::text, 'g'::text) AS "Naam",
    rpp.description AS "SGBPPeriode.Omschrijving",
    ((date_part('year'::text, rpp.period_start) || '-'::text) || date_part('year'::text, rpp.period_end)) AS "UitvoeringIn",
    regexp_replace((sw_supp_measure_eu_type.code)::text, '\r|\n'::text, ''::text, 'g'::text) AS "KRWmaatregel.Code",
    sw_supp_measure_eu_type.name AS "KRWmaatregel.Naam",
    sw_supp_measure_eu_type.hoofdcategorie AS "Hoofdcategorie",
    sw_supp_measure_eu_type.index AS "Index",
    sw_supp_measure_eu_type.klasse AS "SGBP_Klasse",
    sw_supp_measure_eu_type.harmonisatie AS "SGBP_Harmonisatie",
    sw_supp_measure_eu_type.code_sgbp AS "SGBP_code",
    sw_supp_measure_eu_type.artikel_sgbp AS "SGBP_artikel",
    sw_supp_measure_eu_type.tablkop_sgbp AS "SGBP_Hoofdcategorie",
    regexp_replace((level_of_area_type.code)::text, '\r|\n'::text, ''::text, 'g'::text) AS "KRWMaatregelNiveau.Code",
    regexp_replace((level_of_area_type.description)::text, '\r|\n'::text, ''::text, 'g'::text) AS "KRWMaatregelNiveau.Omschrijving",
    array_to_string(ARRAY( SELECT DISTINCT regexp_replace((ho.inspire_id_local_id)::text, '\r|\n'::text, ''::text, 'g'::text) AS regexp_replace
           FROM (hydro_object ho
             JOIN measure_per_man_reg_or_restr_zone mz ON ((mz.mrz_id = ho.hdo_id)))
          WHERE (mz.mtm_id = maatregelen.mtm_id)), '|'::text) AS "HoortbijKRWwaterlichaam",
    stroomgebieddistrict.inspire_id_local_id AS "KRWstroomgebiedDistrict.Code",
    supp_add_measure_type.is_additional_measure AS "OpnameInSGBPJN",
    regexp_replace((organisation_category_type.code)::text, '\r|\n'::text, ''::text, 'g'::text) AS "Initiatiefnemer.Code",
    regexp_replace(supp_add_measure_type.initiative_party, '\r|\n'::text, ''::text, 'g'::text) AS "Initiatiefnemer.Naam",
    array_to_string(ARRAY( SELECT DISTINCT regexp_replace((t.code)::text, '\r|\n'::text, ''::text, 'g'::text) AS regexp_replace
           FROM (monitored_measure_eu_fund m
             JOIN eu_fund_type t ON ((t.euf_id = m.euf_id)))
          WHERE (m.mtm_id = maatregelen.mtm_id)), '|'::text) AS "EUFonds.Code",
    array_to_string(ARRAY( SELECT DISTINCT regexp_replace((vbg."Identificatie")::text, '\r|\n'::text, ''::text, 'g'::text) AS regexp_replace
           FROM (vw_beschermdegebieden vbg
             JOIN measure_per_man_protected_area mpmpa ON ((mpmpa.wpa_id = vbg."DB_ID")))
          WHERE ((mpmpa.mtm_id = maatregelen.mtm_id) AND (vbg."Versie_ID" = river_basin_management_plan.wkrv_id))), '|'::text) AS "RelatieMetNatura2000Gebied",
    array_to_string(ARRAY( SELECT DISTINCT regexp_replace((vgo."Identificatie")::text, '\r|\n'::text, ''::text, 'g'::text) AS regexp_replace
           FROM (vw_gw_onttrekking vgo
             JOIN measure_per_abstraction_point mpap ON ((mpap.asp_id = vgo."DB_ID")))
          WHERE ((mpap.mtm_id = maatregelen.mtm_id) AND (vgo.wkr_versie = river_basin_management_plan.wkrv_id))), '|'::text) AS "RelatieMetWaterwinning",
    river_basin_management_plan.wkrv_id AS versie,
    supp_add_measure_type.amount_value AS "OmvangNumeriekeWaarde",
    regexp_replace((eenheid_type.code)::text, '\r|\n'::text, ''::text, 'g'::text) AS omvangeenheidcode,
    mp1.amount_value AS "Plan",
    mp2.amount_value AS "Uitvoering",
    mp3.amount_value AS "Uitgevoerd",
    mp4.amount_value AS "Gefaseerd",
    mp5.amount_value AS "Vervangen",
    mp6.amount_value AS "Ingetrokken",
    mp1.year AS "Jaar_voortgang"
   FROM ((((((((((((((((monitored_measure maatregelen
     JOIN supp_add_measure_type ON ((supp_add_measure_type.smnl_id = maatregelen.mtm_id)))
     JOIN sw_supp_measure_eu_type ON ((sw_supp_measure_eu_type.smeu_id = supp_add_measure_type.smeu_id)))
     JOIN eenheid_type ON ((eenheid_type.eenh_id = sw_supp_measure_eu_type.eenh_id)))
     JOIN namespace_type wb_nst ON ((wb_nst.ns_id = supp_add_measure_type.namespace_id)))
     JOIN report_version ON ((report_version.rpv_id = maatregelen.rpv_id)))
     JOIN reporting_period rpp ON ((rpp.rpp_id = report_version.rpp_id)))
     JOIN level_of_area_type ON ((level_of_area_type.loa_id = maatregelen.level_of_measure_id)))
     JOIN organisation_category_type ON ((organisation_category_type.ocat_id = supp_add_measure_type.initiative_party_ocat_id)))
     JOIN river_basin_management_plan ON ((river_basin_management_plan.rbmp_id = supp_add_measure_type.rbmp_id)))
     JOIN hydro_object stroomgebieddistrict ON ((stroomgebieddistrict.hdo_id = river_basin_management_plan.rbd_id)))
     LEFT JOIN ( SELECT measure_progress.amount_value,
            measure_progress.year,
            measure_progress.mtm_id
           FROM measure_progress
          WHERE ((measure_progress.mst_id = 1) AND (measure_progress.year = 2011))) mp1 ON ((mp1.mtm_id = maatregelen.mtm_id)))
     LEFT JOIN ( SELECT measure_progress.amount_value,
            measure_progress.year,
            measure_progress.mtm_id
           FROM measure_progress
          WHERE ((measure_progress.mst_id = 2) AND (measure_progress.year = 2011))) mp2 ON ((mp2.mtm_id = maatregelen.mtm_id)))
     LEFT JOIN ( SELECT measure_progress.amount_value,
            measure_progress.year,
            measure_progress.mtm_id
           FROM measure_progress
          WHERE ((measure_progress.mst_id = 3) AND (measure_progress.year = 2011))) mp3 ON ((mp3.mtm_id = maatregelen.mtm_id)))
     LEFT JOIN ( SELECT measure_progress.amount_value,
            measure_progress.year,
            measure_progress.mtm_id
           FROM measure_progress
          WHERE ((measure_progress.mst_id = 4) AND (measure_progress.year = 2011))) mp4 ON ((mp4.mtm_id = maatregelen.mtm_id)))
     LEFT JOIN ( SELECT measure_progress.amount_value,
            measure_progress.year,
            measure_progress.mtm_id
           FROM measure_progress
          WHERE ((measure_progress.mst_id = 5) AND (measure_progress.year = 2011))) mp5 ON ((mp5.mtm_id = maatregelen.mtm_id)))
     LEFT JOIN ( SELECT measure_progress.amount_value,
            measure_progress.year,
            measure_progress.mtm_id
           FROM measure_progress
          WHERE ((measure_progress.mst_id = 6) AND (measure_progress.year = 2011))) mp6 ON ((mp6.mtm_id = maatregelen.mtm_id)))
  ORDER BY supp_add_measure_type.local_id;


--
-- Name: vw_maatregelen_dgrw_2012; Type: VIEW; Schema: public; Owner: -
--

CREATE VIEW vw_maatregelen_dgrw_2012 AS
 SELECT maatregelen.mtm_id AS "DB_ID",
    ('NL'::text || (wb_nst.code)::text) AS "Namespace",
    wb_nst.descrption AS "Waterbeheerder_Naam",
    regexp_replace((supp_add_measure_type.local_id)::text, '\r|\n'::text, ''::text, 'g'::text) AS "LokaalID",
    regexp_replace((supp_add_measure_type.measure_name)::text, '\r|\n'::text, ''::text, 'g'::text) AS "Naam",
    rpp.description AS "SGBPPeriode.Omschrijving",
    ((date_part('year'::text, rpp.period_start) || '-'::text) || date_part('year'::text, rpp.period_end)) AS "UitvoeringIn",
    regexp_replace((sw_supp_measure_eu_type.code)::text, '\r|\n'::text, ''::text, 'g'::text) AS "KRWmaatregel.Code",
    sw_supp_measure_eu_type.name AS "KRWmaatregel.Naam",
    sw_supp_measure_eu_type.hoofdcategorie AS "Hoofdcategorie",
    sw_supp_measure_eu_type.index AS "Index",
    sw_supp_measure_eu_type.klasse AS "SGBP_Klasse",
    sw_supp_measure_eu_type.harmonisatie AS "SGBP_Harmonisatie",
    sw_supp_measure_eu_type.code_sgbp AS "SGBP_code",
    sw_supp_measure_eu_type.artikel_sgbp AS "SGBP_artikel",
    sw_supp_measure_eu_type.tablkop_sgbp AS "SGBP_Hoofdcategorie",
    regexp_replace((level_of_area_type.code)::text, '\r|\n'::text, ''::text, 'g'::text) AS "KRWMaatregelNiveau.Code",
    regexp_replace((level_of_area_type.description)::text, '\r|\n'::text, ''::text, 'g'::text) AS "KRWMaatregelNiveau.Omschrijving",
    array_to_string(ARRAY( SELECT DISTINCT regexp_replace((ho.inspire_id_local_id)::text, '\r|\n'::text, ''::text, 'g'::text) AS regexp_replace
           FROM (hydro_object ho
             JOIN measure_per_man_reg_or_restr_zone mz ON ((mz.mrz_id = ho.hdo_id)))
          WHERE (mz.mtm_id = maatregelen.mtm_id)), '|'::text) AS "HoortbijKRWwaterlichaam",
    stroomgebieddistrict.inspire_id_local_id AS "KRWstroomgebiedDistrict.Code",
    supp_add_measure_type.is_additional_measure AS "OpnameInSGBPJN",
    regexp_replace((organisation_category_type.code)::text, '\r|\n'::text, ''::text, 'g'::text) AS "Initiatiefnemer.Code",
    regexp_replace(supp_add_measure_type.initiative_party, '\r|\n'::text, ''::text, 'g'::text) AS "Initiatiefnemer.Naam",
    array_to_string(ARRAY( SELECT DISTINCT regexp_replace((t.code)::text, '\r|\n'::text, ''::text, 'g'::text) AS regexp_replace
           FROM (monitored_measure_eu_fund m
             JOIN eu_fund_type t ON ((t.euf_id = m.euf_id)))
          WHERE (m.mtm_id = maatregelen.mtm_id)), '|'::text) AS "EUFonds.Code",
    array_to_string(ARRAY( SELECT DISTINCT regexp_replace((vbg."Identificatie")::text, '\r|\n'::text, ''::text, 'g'::text) AS regexp_replace
           FROM (vw_beschermdegebieden vbg
             JOIN measure_per_man_protected_area mpmpa ON ((mpmpa.wpa_id = vbg."DB_ID")))
          WHERE ((mpmpa.mtm_id = maatregelen.mtm_id) AND (vbg."Versie_ID" = river_basin_management_plan.wkrv_id))), '|'::text) AS "RelatieMetNatura2000Gebied",
    array_to_string(ARRAY( SELECT DISTINCT regexp_replace((vgo."Identificatie")::text, '\r|\n'::text, ''::text, 'g'::text) AS regexp_replace
           FROM (vw_gw_onttrekking vgo
             JOIN measure_per_abstraction_point mpap ON ((mpap.asp_id = vgo."DB_ID")))
          WHERE ((mpap.mtm_id = maatregelen.mtm_id) AND (vgo.wkr_versie = river_basin_management_plan.wkrv_id))), '|'::text) AS "RelatieMetWaterwinning",
    river_basin_management_plan.wkrv_id AS versie,
    supp_add_measure_type.amount_value AS "OmvangNumeriekeWaarde",
    regexp_replace((eenheid_type.code)::text, '\r|\n'::text, ''::text, 'g'::text) AS omvangeenheidcode,
    mp1.amount_value AS "Plan",
    mp2.amount_value AS "Uitvoering",
    mp3.amount_value AS "Uitgevoerd",
    mp4.amount_value AS "Gefaseerd",
    mp5.amount_value AS "Vervangen",
    mp6.amount_value AS "Ingetrokken",
    mp1.year AS "Jaar_voortgang"
   FROM ((((((((((((((((monitored_measure maatregelen
     JOIN supp_add_measure_type ON ((supp_add_measure_type.smnl_id = maatregelen.mtm_id)))
     JOIN sw_supp_measure_eu_type ON ((sw_supp_measure_eu_type.smeu_id = supp_add_measure_type.smeu_id)))
     JOIN eenheid_type ON ((eenheid_type.eenh_id = sw_supp_measure_eu_type.eenh_id)))
     JOIN namespace_type wb_nst ON ((wb_nst.ns_id = supp_add_measure_type.namespace_id)))
     JOIN report_version ON ((report_version.rpv_id = maatregelen.rpv_id)))
     JOIN reporting_period rpp ON ((rpp.rpp_id = report_version.rpp_id)))
     JOIN level_of_area_type ON ((level_of_area_type.loa_id = maatregelen.level_of_measure_id)))
     JOIN organisation_category_type ON ((organisation_category_type.ocat_id = supp_add_measure_type.initiative_party_ocat_id)))
     JOIN river_basin_management_plan ON ((river_basin_management_plan.rbmp_id = supp_add_measure_type.rbmp_id)))
     JOIN hydro_object stroomgebieddistrict ON ((stroomgebieddistrict.hdo_id = river_basin_management_plan.rbd_id)))
     LEFT JOIN ( SELECT measure_progress.amount_value,
            measure_progress.year,
            measure_progress.mtm_id
           FROM measure_progress
          WHERE ((measure_progress.mst_id = 1) AND (measure_progress.year = 2012))) mp1 ON ((mp1.mtm_id = maatregelen.mtm_id)))
     LEFT JOIN ( SELECT measure_progress.amount_value,
            measure_progress.year,
            measure_progress.mtm_id
           FROM measure_progress
          WHERE ((measure_progress.mst_id = 2) AND (measure_progress.year = 2012))) mp2 ON ((mp2.mtm_id = maatregelen.mtm_id)))
     LEFT JOIN ( SELECT measure_progress.amount_value,
            measure_progress.year,
            measure_progress.mtm_id
           FROM measure_progress
          WHERE ((measure_progress.mst_id = 3) AND (measure_progress.year = 2012))) mp3 ON ((mp3.mtm_id = maatregelen.mtm_id)))
     LEFT JOIN ( SELECT measure_progress.amount_value,
            measure_progress.year,
            measure_progress.mtm_id
           FROM measure_progress
          WHERE ((measure_progress.mst_id = 4) AND (measure_progress.year = 2012))) mp4 ON ((mp4.mtm_id = maatregelen.mtm_id)))
     LEFT JOIN ( SELECT measure_progress.amount_value,
            measure_progress.year,
            measure_progress.mtm_id
           FROM measure_progress
          WHERE ((measure_progress.mst_id = 5) AND (measure_progress.year = 2012))) mp5 ON ((mp5.mtm_id = maatregelen.mtm_id)))
     LEFT JOIN ( SELECT measure_progress.amount_value,
            measure_progress.year,
            measure_progress.mtm_id
           FROM measure_progress
          WHERE ((measure_progress.mst_id = 6) AND (measure_progress.year = 2012))) mp6 ON ((mp6.mtm_id = maatregelen.mtm_id)))
  ORDER BY supp_add_measure_type.local_id;


--
-- Name: vw_maatregelen_dgrw_2013; Type: VIEW; Schema: public; Owner: -
--

CREATE VIEW vw_maatregelen_dgrw_2013 AS
 SELECT maatregelen.mtm_id AS "DB_ID",
    ('NL'::text || (wb_nst.code)::text) AS "Namespace",
    wb_nst.descrption AS "Waterbeheerder_Naam",
    regexp_replace((supp_add_measure_type.local_id)::text, '\r|\n'::text, ''::text, 'g'::text) AS "LokaalID",
    regexp_replace((supp_add_measure_type.measure_name)::text, '\r|\n'::text, ''::text, 'g'::text) AS "Naam",
    rpp.description AS "SGBPPeriode.Omschrijving",
    ((date_part('year'::text, rpp.period_start) || '-'::text) || date_part('year'::text, rpp.period_end)) AS "UitvoeringIn",
    regexp_replace((sw_supp_measure_eu_type.code)::text, '\r|\n'::text, ''::text, 'g'::text) AS "KRWmaatregel.Code",
    sw_supp_measure_eu_type.name AS "KRWmaatregel.Naam",
    sw_supp_measure_eu_type.hoofdcategorie AS "Hoofdcategorie",
    sw_supp_measure_eu_type.index AS "Index",
    sw_supp_measure_eu_type.klasse AS "SGBP_Klasse",
    sw_supp_measure_eu_type.harmonisatie AS "SGBP_Harmonisatie",
    sw_supp_measure_eu_type.code_sgbp AS "SGBP_code",
    sw_supp_measure_eu_type.artikel_sgbp AS "SGBP_artikel",
    sw_supp_measure_eu_type.tablkop_sgbp AS "SGBP_Hoofdcategorie",
    regexp_replace((level_of_area_type.code)::text, '\r|\n'::text, ''::text, 'g'::text) AS "KRWMaatregelNiveau.Code",
    regexp_replace((level_of_area_type.description)::text, '\r|\n'::text, ''::text, 'g'::text) AS "KRWMaatregelNiveau.Omschrijving",
    array_to_string(ARRAY( SELECT DISTINCT regexp_replace((ho.inspire_id_local_id)::text, '\r|\n'::text, ''::text, 'g'::text) AS regexp_replace
           FROM (hydro_object ho
             JOIN measure_per_man_reg_or_restr_zone mz ON ((mz.mrz_id = ho.hdo_id)))
          WHERE (mz.mtm_id = maatregelen.mtm_id)), '|'::text) AS "HoortbijKRWwaterlichaam",
    stroomgebieddistrict.inspire_id_local_id AS "KRWstroomgebiedDistrict.Code",
    supp_add_measure_type.is_additional_measure AS "OpnameInSGBPJN",
    regexp_replace((organisation_category_type.code)::text, '\r|\n'::text, ''::text, 'g'::text) AS "Initiatiefnemer.Code",
    regexp_replace(supp_add_measure_type.initiative_party, '\r|\n'::text, ''::text, 'g'::text) AS "Initiatiefnemer.Naam",
    array_to_string(ARRAY( SELECT DISTINCT regexp_replace((t.code)::text, '\r|\n'::text, ''::text, 'g'::text) AS regexp_replace
           FROM (monitored_measure_eu_fund m
             JOIN eu_fund_type t ON ((t.euf_id = m.euf_id)))
          WHERE (m.mtm_id = maatregelen.mtm_id)), '|'::text) AS "EUFonds.Code",
    array_to_string(ARRAY( SELECT DISTINCT regexp_replace((vbg."Identificatie")::text, '\r|\n'::text, ''::text, 'g'::text) AS regexp_replace
           FROM (vw_beschermdegebieden vbg
             JOIN measure_per_man_protected_area mpmpa ON ((mpmpa.wpa_id = vbg."DB_ID")))
          WHERE ((mpmpa.mtm_id = maatregelen.mtm_id) AND (vbg."Versie_ID" = river_basin_management_plan.wkrv_id))), '|'::text) AS "RelatieMetNatura2000Gebied",
    array_to_string(ARRAY( SELECT DISTINCT regexp_replace((vgo."Identificatie")::text, '\r|\n'::text, ''::text, 'g'::text) AS regexp_replace
           FROM (vw_gw_onttrekking vgo
             JOIN measure_per_abstraction_point mpap ON ((mpap.asp_id = vgo."DB_ID")))
          WHERE ((mpap.mtm_id = maatregelen.mtm_id) AND (vgo.wkr_versie = river_basin_management_plan.wkrv_id))), '|'::text) AS "RelatieMetWaterwinning",
    river_basin_management_plan.wkrv_id AS versie,
    supp_add_measure_type.amount_value AS "OmvangNumeriekeWaarde",
    regexp_replace((eenheid_type.code)::text, '\r|\n'::text, ''::text, 'g'::text) AS omvangeenheidcode,
    mp1.amount_value AS "Plan",
    mp2.amount_value AS "Uitvoering",
    mp3.amount_value AS "Uitgevoerd",
    mp4.amount_value AS "Gefaseerd",
    mp5.amount_value AS "Vervangen",
    mp6.amount_value AS "Ingetrokken",
    mp1.year AS "Jaar_voortgang"
   FROM ((((((((((((((((monitored_measure maatregelen
     JOIN supp_add_measure_type ON ((supp_add_measure_type.smnl_id = maatregelen.mtm_id)))
     JOIN sw_supp_measure_eu_type ON ((sw_supp_measure_eu_type.smeu_id = supp_add_measure_type.smeu_id)))
     JOIN eenheid_type ON ((eenheid_type.eenh_id = sw_supp_measure_eu_type.eenh_id)))
     JOIN namespace_type wb_nst ON ((wb_nst.ns_id = supp_add_measure_type.namespace_id)))
     JOIN report_version ON ((report_version.rpv_id = maatregelen.rpv_id)))
     JOIN reporting_period rpp ON ((rpp.rpp_id = report_version.rpp_id)))
     JOIN level_of_area_type ON ((level_of_area_type.loa_id = maatregelen.level_of_measure_id)))
     JOIN organisation_category_type ON ((organisation_category_type.ocat_id = supp_add_measure_type.initiative_party_ocat_id)))
     JOIN river_basin_management_plan ON ((river_basin_management_plan.rbmp_id = supp_add_measure_type.rbmp_id)))
     JOIN hydro_object stroomgebieddistrict ON ((stroomgebieddistrict.hdo_id = river_basin_management_plan.rbd_id)))
     LEFT JOIN ( SELECT measure_progress.amount_value,
            measure_progress.year,
            measure_progress.mtm_id
           FROM measure_progress
          WHERE ((measure_progress.mst_id = 1) AND (measure_progress.year = 2013))) mp1 ON ((mp1.mtm_id = maatregelen.mtm_id)))
     LEFT JOIN ( SELECT measure_progress.amount_value,
            measure_progress.year,
            measure_progress.mtm_id
           FROM measure_progress
          WHERE ((measure_progress.mst_id = 2) AND (measure_progress.year = 2013))) mp2 ON ((mp2.mtm_id = maatregelen.mtm_id)))
     LEFT JOIN ( SELECT measure_progress.amount_value,
            measure_progress.year,
            measure_progress.mtm_id
           FROM measure_progress
          WHERE ((measure_progress.mst_id = 3) AND (measure_progress.year = 2013))) mp3 ON ((mp3.mtm_id = maatregelen.mtm_id)))
     LEFT JOIN ( SELECT measure_progress.amount_value,
            measure_progress.year,
            measure_progress.mtm_id
           FROM measure_progress
          WHERE ((measure_progress.mst_id = 4) AND (measure_progress.year = 2013))) mp4 ON ((mp4.mtm_id = maatregelen.mtm_id)))
     LEFT JOIN ( SELECT measure_progress.amount_value,
            measure_progress.year,
            measure_progress.mtm_id
           FROM measure_progress
          WHERE ((measure_progress.mst_id = 5) AND (measure_progress.year = 2013))) mp5 ON ((mp5.mtm_id = maatregelen.mtm_id)))
     LEFT JOIN ( SELECT measure_progress.amount_value,
            measure_progress.year,
            measure_progress.mtm_id
           FROM measure_progress
          WHERE ((measure_progress.mst_id = 6) AND (measure_progress.year = 2013))) mp6 ON ((mp6.mtm_id = maatregelen.mtm_id)))
  ORDER BY supp_add_measure_type.local_id;


--
-- Name: vw_maatregelen_dgrw_2014; Type: VIEW; Schema: public; Owner: -
--

CREATE VIEW vw_maatregelen_dgrw_2014 AS
 SELECT maatregelen.mtm_id AS "DB_ID",
    ('NL'::text || (wb_nst.code)::text) AS "Namespace",
    wb_nst.descrption AS "Waterbeheerder_Naam",
    regexp_replace((supp_add_measure_type.local_id)::text, '\r|\n'::text, ''::text, 'g'::text) AS "LokaalID",
    regexp_replace((supp_add_measure_type.measure_name)::text, '\r|\n'::text, ''::text, 'g'::text) AS "Naam",
    rpp.description AS "SGBPPeriode.Omschrijving",
    ((date_part('year'::text, rpp.period_start) || '-'::text) || date_part('year'::text, rpp.period_end)) AS "UitvoeringIn",
    regexp_replace((sw_supp_measure_eu_type.code)::text, '\r|\n'::text, ''::text, 'g'::text) AS "KRWmaatregel.Code",
    sw_supp_measure_eu_type.name AS "KRWmaatregel.Naam",
    sw_supp_measure_eu_type.hoofdcategorie AS "Hoofdcategorie",
    sw_supp_measure_eu_type.index AS "Index",
    sw_supp_measure_eu_type.klasse AS "SGBP_Klasse",
    sw_supp_measure_eu_type.harmonisatie AS "SGBP_Harmonisatie",
    sw_supp_measure_eu_type.code_sgbp AS "SGBP_code",
    sw_supp_measure_eu_type.artikel_sgbp AS "SGBP_artikel",
    sw_supp_measure_eu_type.tablkop_sgbp AS "SGBP_Hoofdcategorie",
    regexp_replace((level_of_area_type.code)::text, '\r|\n'::text, ''::text, 'g'::text) AS "KRWMaatregelNiveau.Code",
    regexp_replace((level_of_area_type.description)::text, '\r|\n'::text, ''::text, 'g'::text) AS "KRWMaatregelNiveau.Omschrijving",
    array_to_string(ARRAY( SELECT DISTINCT regexp_replace((ho.inspire_id_local_id)::text, '\r|\n'::text, ''::text, 'g'::text) AS regexp_replace
           FROM (hydro_object ho
             JOIN measure_per_man_reg_or_restr_zone mz ON ((mz.mrz_id = ho.hdo_id)))
          WHERE (mz.mtm_id = maatregelen.mtm_id)), '|'::text) AS "HoortbijKRWwaterlichaam",
    stroomgebieddistrict.inspire_id_local_id AS "KRWstroomgebiedDistrict.Code",
    supp_add_measure_type.is_additional_measure AS "OpnameInSGBPJN",
    regexp_replace((organisation_category_type.code)::text, '\r|\n'::text, ''::text, 'g'::text) AS "Initiatiefnemer.Code",
    regexp_replace(supp_add_measure_type.initiative_party, '\r|\n'::text, ''::text, 'g'::text) AS "Initiatiefnemer.Naam",
    array_to_string(ARRAY( SELECT DISTINCT regexp_replace((t.code)::text, '\r|\n'::text, ''::text, 'g'::text) AS regexp_replace
           FROM (monitored_measure_eu_fund m
             JOIN eu_fund_type t ON ((t.euf_id = m.euf_id)))
          WHERE (m.mtm_id = maatregelen.mtm_id)), '|'::text) AS "EUFonds.Code",
    array_to_string(ARRAY( SELECT DISTINCT regexp_replace((vbg."Identificatie")::text, '\r|\n'::text, ''::text, 'g'::text) AS regexp_replace
           FROM (vw_beschermdegebieden vbg
             JOIN measure_per_man_protected_area mpmpa ON ((mpmpa.wpa_id = vbg."DB_ID")))
          WHERE ((mpmpa.mtm_id = maatregelen.mtm_id) AND (vbg."Versie_ID" = river_basin_management_plan.wkrv_id))), '|'::text) AS "RelatieMetNatura2000Gebied",
    array_to_string(ARRAY( SELECT DISTINCT regexp_replace((vgo."Identificatie")::text, '\r|\n'::text, ''::text, 'g'::text) AS regexp_replace
           FROM (vw_gw_onttrekking vgo
             JOIN measure_per_abstraction_point mpap ON ((mpap.asp_id = vgo."DB_ID")))
          WHERE ((mpap.mtm_id = maatregelen.mtm_id) AND (vgo.wkr_versie = river_basin_management_plan.wkrv_id))), '|'::text) AS "RelatieMetWaterwinning",
    river_basin_management_plan.wkrv_id AS versie,
    supp_add_measure_type.amount_value AS "OmvangNumeriekeWaarde",
    regexp_replace((eenheid_type.code)::text, '\r|\n'::text, ''::text, 'g'::text) AS omvangeenheidcode,
    mp1.amount_value AS "Plan",
    mp2.amount_value AS "Uitvoering",
    mp3.amount_value AS "Uitgevoerd",
    mp4.amount_value AS "Gefaseerd",
    mp5.amount_value AS "Vervangen",
    mp6.amount_value AS "Ingetrokken",
    mp1.year AS "Jaar_voortgang"
   FROM ((((((((((((((((monitored_measure maatregelen
     JOIN supp_add_measure_type ON ((supp_add_measure_type.smnl_id = maatregelen.mtm_id)))
     JOIN sw_supp_measure_eu_type ON ((sw_supp_measure_eu_type.smeu_id = supp_add_measure_type.smeu_id)))
     JOIN eenheid_type ON ((eenheid_type.eenh_id = sw_supp_measure_eu_type.eenh_id)))
     JOIN namespace_type wb_nst ON ((wb_nst.ns_id = supp_add_measure_type.namespace_id)))
     JOIN report_version ON ((report_version.rpv_id = maatregelen.rpv_id)))
     JOIN reporting_period rpp ON ((rpp.rpp_id = report_version.rpp_id)))
     JOIN level_of_area_type ON ((level_of_area_type.loa_id = maatregelen.level_of_measure_id)))
     JOIN organisation_category_type ON ((organisation_category_type.ocat_id = supp_add_measure_type.initiative_party_ocat_id)))
     JOIN river_basin_management_plan ON ((river_basin_management_plan.rbmp_id = supp_add_measure_type.rbmp_id)))
     JOIN hydro_object stroomgebieddistrict ON ((stroomgebieddistrict.hdo_id = river_basin_management_plan.rbd_id)))
     LEFT JOIN ( SELECT measure_progress.amount_value,
            measure_progress.year,
            measure_progress.mtm_id
           FROM measure_progress
          WHERE ((measure_progress.mst_id = 1) AND (measure_progress.year = 2014))) mp1 ON ((mp1.mtm_id = maatregelen.mtm_id)))
     LEFT JOIN ( SELECT measure_progress.amount_value,
            measure_progress.year,
            measure_progress.mtm_id
           FROM measure_progress
          WHERE ((measure_progress.mst_id = 2) AND (measure_progress.year = 2014))) mp2 ON ((mp2.mtm_id = maatregelen.mtm_id)))
     LEFT JOIN ( SELECT measure_progress.amount_value,
            measure_progress.year,
            measure_progress.mtm_id
           FROM measure_progress
          WHERE ((measure_progress.mst_id = 3) AND (measure_progress.year = 2014))) mp3 ON ((mp3.mtm_id = maatregelen.mtm_id)))
     LEFT JOIN ( SELECT measure_progress.amount_value,
            measure_progress.year,
            measure_progress.mtm_id
           FROM measure_progress
          WHERE ((measure_progress.mst_id = 4) AND (measure_progress.year = 2014))) mp4 ON ((mp4.mtm_id = maatregelen.mtm_id)))
     LEFT JOIN ( SELECT measure_progress.amount_value,
            measure_progress.year,
            measure_progress.mtm_id
           FROM measure_progress
          WHERE ((measure_progress.mst_id = 5) AND (measure_progress.year = 2014))) mp5 ON ((mp5.mtm_id = maatregelen.mtm_id)))
     LEFT JOIN ( SELECT measure_progress.amount_value,
            measure_progress.year,
            measure_progress.mtm_id
           FROM measure_progress
          WHERE ((measure_progress.mst_id = 6) AND (measure_progress.year = 2014))) mp6 ON ((mp6.mtm_id = maatregelen.mtm_id)))
  ORDER BY supp_add_measure_type.local_id;


--
-- Name: vw_maatregelen_dgrw_2015; Type: VIEW; Schema: public; Owner: -
--

CREATE VIEW vw_maatregelen_dgrw_2015 AS
 SELECT maatregelen.mtm_id AS "DB_ID",
    ('NL'::text || (wb_nst.code)::text) AS "Namespace",
    wb_nst.descrption AS "Waterbeheerder_Naam",
    regexp_replace((supp_add_measure_type.local_id)::text, '\r|\n'::text, ''::text, 'g'::text) AS "LokaalID",
    regexp_replace((supp_add_measure_type.measure_name)::text, '\r|\n'::text, ''::text, 'g'::text) AS "Naam",
    rpp.description AS "SGBPPeriode.Omschrijving",
    ((date_part('year'::text, rpp.period_start) || '-'::text) || date_part('year'::text, rpp.period_end)) AS "UitvoeringIn",
    regexp_replace((sw_supp_measure_eu_type.code)::text, '\r|\n'::text, ''::text, 'g'::text) AS "KRWmaatregel.Code",
    sw_supp_measure_eu_type.name AS "KRWmaatregel.Naam",
    sw_supp_measure_eu_type.hoofdcategorie AS "Hoofdcategorie",
    sw_supp_measure_eu_type.index AS "Index",
    sw_supp_measure_eu_type.klasse AS "SGBP_Klasse",
    sw_supp_measure_eu_type.harmonisatie AS "SGBP_Harmonisatie",
    sw_supp_measure_eu_type.code_sgbp AS "SGBP_code",
    sw_supp_measure_eu_type.artikel_sgbp AS "SGBP_artikel",
    sw_supp_measure_eu_type.tablkop_sgbp AS "SGBP_Hoofdcategorie",
    regexp_replace((level_of_area_type.code)::text, '\r|\n'::text, ''::text, 'g'::text) AS "KRWMaatregelNiveau.Code",
    regexp_replace((level_of_area_type.description)::text, '\r|\n'::text, ''::text, 'g'::text) AS "KRWMaatregelNiveau.Omschrijving",
    array_to_string(ARRAY( SELECT DISTINCT regexp_replace((ho.inspire_id_local_id)::text, '\r|\n'::text, ''::text, 'g'::text) AS regexp_replace
           FROM (hydro_object ho
             JOIN measure_per_man_reg_or_restr_zone mz ON ((mz.mrz_id = ho.hdo_id)))
          WHERE (mz.mtm_id = maatregelen.mtm_id)), '|'::text) AS "HoortbijKRWwaterlichaam",
    stroomgebieddistrict.inspire_id_local_id AS "KRWstroomgebiedDistrict.Code",
    supp_add_measure_type.is_additional_measure AS "OpnameInSGBPJN",
    regexp_replace((organisation_category_type.code)::text, '\r|\n'::text, ''::text, 'g'::text) AS "Initiatiefnemer.Code",
    regexp_replace(supp_add_measure_type.initiative_party, '\r|\n'::text, ''::text, 'g'::text) AS "Initiatiefnemer.Naam",
    array_to_string(ARRAY( SELECT DISTINCT regexp_replace((t.code)::text, '\r|\n'::text, ''::text, 'g'::text) AS regexp_replace
           FROM (monitored_measure_eu_fund m
             JOIN eu_fund_type t ON ((t.euf_id = m.euf_id)))
          WHERE (m.mtm_id = maatregelen.mtm_id)), '|'::text) AS "EUFonds.Code",
    array_to_string(ARRAY( SELECT DISTINCT regexp_replace((vbg."Identificatie")::text, '\r|\n'::text, ''::text, 'g'::text) AS regexp_replace
           FROM (vw_beschermdegebieden vbg
             JOIN measure_per_man_protected_area mpmpa ON ((mpmpa.wpa_id = vbg."DB_ID")))
          WHERE ((mpmpa.mtm_id = maatregelen.mtm_id) AND (vbg."Versie_ID" = river_basin_management_plan.wkrv_id))), '|'::text) AS "RelatieMetNatura2000Gebied",
    array_to_string(ARRAY( SELECT DISTINCT regexp_replace((vgo."Identificatie")::text, '\r|\n'::text, ''::text, 'g'::text) AS regexp_replace
           FROM (vw_gw_onttrekking vgo
             JOIN measure_per_abstraction_point mpap ON ((mpap.asp_id = vgo."DB_ID")))
          WHERE ((mpap.mtm_id = maatregelen.mtm_id) AND (vgo.wkr_versie = river_basin_management_plan.wkrv_id))), '|'::text) AS "RelatieMetWaterwinning",
    river_basin_management_plan.wkrv_id AS versie,
    supp_add_measure_type.amount_value AS "OmvangNumeriekeWaarde",
    regexp_replace((eenheid_type.code)::text, '\r|\n'::text, ''::text, 'g'::text) AS omvangeenheidcode,
    mp1.amount_value AS "Plan",
    mp2.amount_value AS "Uitvoering",
    mp3.amount_value AS "Uitgevoerd",
    mp4.amount_value AS "Gefaseerd",
    mp5.amount_value AS "Vervangen",
    mp6.amount_value AS "Ingetrokken",
    mp1.year AS "Jaar_voortgang"
   FROM ((((((((((((((((monitored_measure maatregelen
     JOIN supp_add_measure_type ON ((supp_add_measure_type.smnl_id = maatregelen.mtm_id)))
     JOIN sw_supp_measure_eu_type ON ((sw_supp_measure_eu_type.smeu_id = supp_add_measure_type.smeu_id)))
     JOIN eenheid_type ON ((eenheid_type.eenh_id = sw_supp_measure_eu_type.eenh_id)))
     JOIN namespace_type wb_nst ON ((wb_nst.ns_id = supp_add_measure_type.namespace_id)))
     JOIN report_version ON ((report_version.rpv_id = maatregelen.rpv_id)))
     JOIN reporting_period rpp ON ((rpp.rpp_id = report_version.rpp_id)))
     JOIN level_of_area_type ON ((level_of_area_type.loa_id = maatregelen.level_of_measure_id)))
     JOIN organisation_category_type ON ((organisation_category_type.ocat_id = supp_add_measure_type.initiative_party_ocat_id)))
     JOIN river_basin_management_plan ON ((river_basin_management_plan.rbmp_id = supp_add_measure_type.rbmp_id)))
     JOIN hydro_object stroomgebieddistrict ON ((stroomgebieddistrict.hdo_id = river_basin_management_plan.rbd_id)))
     LEFT JOIN ( SELECT measure_progress.amount_value,
            measure_progress.year,
            measure_progress.mtm_id
           FROM measure_progress
          WHERE ((measure_progress.mst_id = 1) AND (measure_progress.year = 2015))) mp1 ON ((mp1.mtm_id = maatregelen.mtm_id)))
     LEFT JOIN ( SELECT measure_progress.amount_value,
            measure_progress.year,
            measure_progress.mtm_id
           FROM measure_progress
          WHERE ((measure_progress.mst_id = 2) AND (measure_progress.year = 2015))) mp2 ON ((mp2.mtm_id = maatregelen.mtm_id)))
     LEFT JOIN ( SELECT measure_progress.amount_value,
            measure_progress.year,
            measure_progress.mtm_id
           FROM measure_progress
          WHERE ((measure_progress.mst_id = 3) AND (measure_progress.year = 2015))) mp3 ON ((mp3.mtm_id = maatregelen.mtm_id)))
     LEFT JOIN ( SELECT measure_progress.amount_value,
            measure_progress.year,
            measure_progress.mtm_id
           FROM measure_progress
          WHERE ((measure_progress.mst_id = 4) AND (measure_progress.year = 2015))) mp4 ON ((mp4.mtm_id = maatregelen.mtm_id)))
     LEFT JOIN ( SELECT measure_progress.amount_value,
            measure_progress.year,
            measure_progress.mtm_id
           FROM measure_progress
          WHERE ((measure_progress.mst_id = 5) AND (measure_progress.year = 2015))) mp5 ON ((mp5.mtm_id = maatregelen.mtm_id)))
     LEFT JOIN ( SELECT measure_progress.amount_value,
            measure_progress.year,
            measure_progress.mtm_id
           FROM measure_progress
          WHERE ((measure_progress.mst_id = 6) AND (measure_progress.year = 2015))) mp6 ON ((mp6.mtm_id = maatregelen.mtm_id)))
  ORDER BY supp_add_measure_type.local_id;


--
-- Name: vw_maatregelen_financieen; Type: VIEW; Schema: public; Owner: -
--

CREATE VIEW vw_maatregelen_financieen AS
 SELECT vw_maatregelen."DB_ID" AS "Maatregel_DB_ID",
    vw_maatregelen."Identifcatie" AS "Maatregel_Identificatie",
    vw_maatregelen."Naam" AS "Maatregel_Naam",
    measure_finance.sum AS "Kosten",
    measure_finance_type.omschrijving
   FROM measure_finance,
    vw_maatregelen,
    measure_finance_type
  WHERE ((vw_maatregelen."DB_ID" = measure_finance.mtm_id) AND (measure_finance_type.mtf_id = measure_finance.mft_id));


--
-- Name: vw_maatregelen_for_crystal_reports; Type: VIEW; Schema: public; Owner: -
--

CREATE VIEW vw_maatregelen_for_crystal_reports AS
 SELECT measure_progress.last_change_time,
    monitored_measure.mtm_id AS "DB_ID",
    measure_progress.amount_value,
    monitored_measure.prime_competent_authority_id,
    reporting_period.rpp_id AS periodeid,
    (reporting_period.description)::character varying(20) AS sqbp_periode,
    (reporting_period.description)::character varying(20) AS periode_sgbp,
    reporting_period.period_start AS rapportageperiodebegin,
    reporting_period.period_end AS rapportageperiodeeind,
    object_state_type.code AS rapportagestatus,
    reporting_period.description AS rapportageperiode,
    report_version.is_public_data AS publiektoegankelijk,
    supp_add_measure_type.local_id AS "Maatregel_Identifcatie",
    supp_add_measure_type.measure_name AS "Maatregel_Naam",
    supp_add_measure_type.measure_description AS "Omschrijving",
    supp_add_measure_type.comment AS "Toelichting",
    supp_add_measure_type.associated_link_desc AS "Bron_Omschrijving",
    level_of_area_type.description AS "Niveau",
    sw_supp_measure_eu_type.name AS "EUType_Omschrijving",
    supp_add_measure_type.amount_value AS "Hoeveelheid",
    eenheid_type.code AS "Eenheid_Code",
    eenheid_type.omschrijving AS "Eenheid_Omschrijving",
    supp_add_measure_type.initiative_party AS "Initiatiefnemer",
    organisation_category_type.omschrijving AS "Initiatiefnemer_Categorie",
    supp_add_measure_type.is_additional_measure AS "Opgenomen_In_SGBP",
    competent_authority.namespace_id AS waterbeheerderid,
    ('NL'::text || (wb_nst.code)::text) AS namespace,
    organisatorische_eenheid.naam,
    organisation_category_type.code AS waterbeheerdercode,
    reporting_period.description AS periode,
    supp_add_measure_type.local_id AS lokaalid,
    supp_add_measure_type.measure_description AS beschrijving,
    supp_add_measure_type.comment AS toelichting,
    measure_status_type.code AS "VoortgangStatus_Code",
    measure_progress.amount_value AS "Hoeveelheid_voortgang",
    measure_progress.reason_substanstial_delay AS "Motivering",
    supp_add_measure_type.amount_value AS omvangnummeriekewaarde,
    supp_add_measure_type.is_additional_measure AS opnameinsgbpjn,
    supp_add_measure_type.initiative_party AS initiatiefnemernaam,
    supp_add_measure_type.is_abstraction_relevant AS relatiemetwaterwinning,
    supp_add_measure_type."is_N2000_relevant" AS relatiemetnatura2000gebied,
    sw_supp_measure_eu_type.code AS maatregelcode,
    level_of_area_type.code AS maatregelniveaucode,
    eenheid_type.code AS omvangeenheidcode,
    organisation_category_type.code AS initiatiefnemersoortcode,
    array_to_string(ARRAY( SELECT DISTINCT regexp_replace((ho.inspire_id_local_id)::text, '\r|\n'::text, ''::text, 'g'::text) AS regexp_replace
           FROM (hydro_object ho
             JOIN measure_per_man_reg_or_restr_zone mz ON ((mz.mrz_id = ho.hdo_id)))
          WHERE (mz.mtm_id = monitored_measure.mtm_id)), '|'::text) AS hoortbijwaterlichamen,
    stroomgebieddistrict.inspire_id_local_id AS stroomgebieddistrictcode,
    measure_progress.year AS "Jaar",
    wkr_version.wkrv_id AS wkr_versie,
    wkr_version.begin_lifespan_version AS wkr_beginversie,
    wkr_version.end_lifespan_version AS wkr_eindversie,
    sw_supp_measure_eu_type.artikel_sgbp AS art11,
    sw_supp_measure_eu_type.tablkop_sgbp AS tabelkop,
    sw_supp_measure_eu_type.code_sgbp AS codesqbp,
    sw_supp_measure_eu_type.hoofdcategorie,
    sw_supp_measure_eu_type.subcategorie,
    sw_supp_measure_eu_type.harmonisatie AS samengevoegdemaatregel
   FROM ((((((((((((((((((((measure_progress
     JOIN monitored_measure ON ((monitored_measure.mtm_id = measure_progress.mtm_id)))
     LEFT JOIN measure_per_man_reg_or_restr_zone ON ((measure_per_man_reg_or_restr_zone.mtm_id = monitored_measure.mtm_id)))
     JOIN supp_add_measure_type ON ((supp_add_measure_type.smnl_id = monitored_measure.mtm_id)))
     JOIN hydro_object ON ((hydro_object.hdo_id = measure_per_man_reg_or_restr_zone.mrz_id)))
     JOIN competentauthority_namespacetype ON ((competentauthority_namespacetype.ns_id = hydro_object.inspire_id_namespace)))
     JOIN competent_authority ON ((competent_authority.ore_id = competentauthority_namespacetype.ore_id)))
     JOIN namespace_type wb_nst ON ((wb_nst.ns_id = competent_authority.namespace_id)))
     JOIN report_version ON ((report_version.rpv_id = monitored_measure.rpv_id)))
     JOIN object_state_type ON ((report_version.ost_id = object_state_type.ost_id)))
     JOIN reporting_period ON ((reporting_period.rpp_id = report_version.rpp_id)))
     JOIN sw_supp_measure_eu_type ON ((sw_supp_measure_eu_type.smeu_id = supp_add_measure_type.smeu_id)))
     JOIN level_of_area_type ON ((level_of_area_type.loa_id = monitored_measure.level_of_measure_id)))
     JOIN eenheid_type ON ((eenheid_type.eenh_id = sw_supp_measure_eu_type.eenh_id)))
     JOIN water_body ON ((water_body.wbd_id = hydro_object.hdo_id)))
     JOIN hydro_object stroomgebieddistrict ON ((stroomgebieddistrict.hdo_id = water_body.rbd_id)))
     JOIN measure_status_type ON ((measure_status_type.mst_id = measure_progress.mst_id)))
     JOIN organisatorische_eenheid ON ((organisatorische_eenheid.ore_id = competent_authority.ore_id)))
     JOIN organisation_category_type ON ((organisation_category_type.ocat_id = organisatorische_eenheid.organisation_category_id)))
     JOIN legislation_reference_type ON ((legislation_reference_type.lgr_id = reporting_period.leg_ref_id)))
     JOIN wkr_version ON ((report_version.wkrv_id = wkr_version.wkrv_id)))
  ORDER BY measure_progress.last_change_time DESC, reporting_period.rpp_id, wb_nst.code, supp_add_measure_type.local_id, supp_add_measure_type.measure_name;


--
-- Name: vw_maatregelen_for_download; Type: VIEW; Schema: public; Owner: -
--

CREATE VIEW vw_maatregelen_for_download AS
 SELECT maatregelen.mtm_id,
    rv2.rpp_id AS periodeid,
    competent_authority.ore_id AS waterbeheerderoreid,
    ('NL'::text || (wb_nst.code)::text) AS waterbeheerdercode,
    regexp_replace((supp_add_measure_type.local_id)::text, '\r|\n'::text, ''::text, 'g'::text) AS maatregelcode,
    regexp_replace((supp_add_measure_type.measure_name)::text, '\r|\n'::text, ''::text, 'g'::text) AS naam,
    rpp.description AS sgbpperiodeomschrijving,
    ((date_part('year'::text, reporting_period.period_start) || '-'::text) || date_part('year'::text, reporting_period.period_end)) AS uitvoeringin,
    regexp_replace((sw_supp_measure_eu_type.code)::text, '\r|\n'::text, ''::text, 'g'::text) AS krwmaatregelcode,
    regexp_replace((supp_add_measure_type.measure_description)::text, '\r|\n'::text, ''::text, 'g'::text) AS toelichting,
    regexp_replace((level_of_area_type.code)::text, '\r|\n'::text, ''::text, 'g'::text) AS krwmaatregelniveaucode,
    array_to_string(ARRAY( SELECT DISTINCT regexp_replace((ho.inspire_id_local_id)::text, '\r|\n'::text, ''::text, 'g'::text) AS regexp_replace
           FROM (hydro_object ho
             JOIN measure_per_man_reg_or_restr_zone mz ON ((mz.mrz_id = ho.hdo_id)))
          WHERE (mz.mtm_id = maatregelen.mtm_id)), '|'::text) AS hoortbijkrwwaterlichaam,
    stroomgebieddistrict.inspire_id_local_id AS krwstroomgebieddistrictcode,
    supp_add_measure_type.amount_value AS omvangnumeriekewaarde,
    regexp_replace((eenheid_type.code)::text, '\r|\n'::text, ''::text, 'g'::text) AS omvangeenheidcode,
    supp_add_measure_type.is_additional_measure AS opnameinsgbp,
    regexp_replace((organisation_category_type.code)::text, '\r|\n'::text, ''::text, 'g'::text) AS initiatiefnemersoortcode,
    regexp_replace(supp_add_measure_type.initiative_party, '\r|\n'::text, ''::text, 'g'::text) AS initiatiefnemernaam,
    array_to_string(ARRAY( SELECT DISTINCT regexp_replace((t.code)::text, '\r|\n'::text, ''::text, 'g'::text) AS regexp_replace
           FROM (monitored_measure_eu_fund m
             JOIN eu_fund_type t ON ((t.euf_id = m.euf_id)))
          WHERE (m.mtm_id = maatregelen.mtm_id)), '|'::text) AS eufondscode,
    array_to_string(ARRAY( SELECT DISTINCT regexp_replace((((mft.omschrijving)::text || '='::text) || mf2.sum), '\r|\n'::text, ''::text, 'g'::text) AS regexp_replace
           FROM (measure_finance mf2
             JOIN measure_finance_type mft ON ((mft.mtf_id = mf2.mft_id)))
          WHERE ((mf2.mtm_id = maatregelen.mtm_id) AND (mf2.mft_id <> 3))), '|'::text) AS kosten,
    array_to_string(ARRAY( SELECT DISTINCT regexp_replace((vbg."Identificatie")::text, '\r|\n'::text, ''::text, 'g'::text) AS regexp_replace
           FROM (vw_beschermdegebieden vbg
             JOIN measure_per_man_protected_area mpmpa ON ((mpmpa.wpa_id = vbg."DB_ID")))
          WHERE ((mpmpa.mtm_id = maatregelen.mtm_id) AND (vbg."Versie_ID" = rv2.wkrv_id))), '|'::text) AS natura2000gebieden,
    array_to_string(ARRAY( SELECT DISTINCT regexp_replace((vgo."Identificatie")::text, '\r|\n'::text, ''::text, 'g'::text) AS regexp_replace
           FROM (vw_gw_onttrekking vgo
             JOIN measure_per_abstraction_point mpap ON ((mpap.asp_id = vgo."DB_ID")))
          WHERE ((mpap.mtm_id = maatregelen.mtm_id) AND (vgo.wkr_versie = rv2.wkrv_id))), '|'::text) AS waterwinningsgebieden
   FROM ((((((((((((((monitored_measure maatregelen
     JOIN supp_add_measure_type ON ((supp_add_measure_type.smnl_id = maatregelen.mtm_id)))
     JOIN sw_supp_measure_eu_type ON ((sw_supp_measure_eu_type.smeu_id = supp_add_measure_type.smeu_id)))
     JOIN eenheid_type ON ((eenheid_type.eenh_id = sw_supp_measure_eu_type.eenh_id)))
     JOIN namespace_type wb_nst ON ((wb_nst.ns_id = supp_add_measure_type.namespace_id)))
     JOIN competentauthority_namespacetype ON ((competentauthority_namespacetype.ns_id = wb_nst.ns_id)))
     JOIN competent_authority ON ((competent_authority.ore_id = competentauthority_namespacetype.ore_id)))
     JOIN report_version ON ((report_version.rpv_id = maatregelen.rpv_id)))
     JOIN reporting_period ON ((reporting_period.rpp_id = report_version.rpp_id)))
     JOIN level_of_area_type ON ((level_of_area_type.loa_id = maatregelen.level_of_measure_id)))
     JOIN organisation_category_type ON ((organisation_category_type.ocat_id = supp_add_measure_type.initiative_party_ocat_id)))
     JOIN river_basin_management_plan ON ((river_basin_management_plan.rbmp_id = supp_add_measure_type.rbmp_id)))
     JOIN hydro_object stroomgebieddistrict ON ((stroomgebieddistrict.hdo_id = river_basin_management_plan.rbd_id)))
     JOIN report_version rv2 ON ((rv2.wkrv_id = river_basin_management_plan.wkrv_id)))
     JOIN reporting_period rpp ON (((rpp.rpp_id = rv2.rpp_id) AND (rv2.begin_lifespan_version <= now()) AND ((rv2.end_lifespan_version > now()) OR (rv2.end_lifespan_version IS NULL)) AND (rpp.leg_ref_id = 1))))
  ORDER BY supp_add_measure_type.local_id;


--
-- Name: vw_maatregelen_volgorde; Type: VIEW; Schema: public; Owner: -
--

CREATE VIEW vw_maatregelen_volgorde AS
 SELECT DISTINCT smeu.code,
    smeu.hoofdcategorie,
    smeu.subcategorie,
    smeu.code_sgbp,
        CASE smeu.code_sgbp
            WHEN 'RO078'::text THEN '01'::text
            WHEN 'RO07'::text THEN '01'::text
            WHEN 'RO08'::text THEN '01'::text
            WHEN 'IM06'::text THEN '02'::text
            WHEN 'IM03'::text THEN '03'::text
            WHEN 'IM12'::text THEN '04'::text
            WHEN 'IM012'::text THEN '05'::text
            WHEN 'IM01'::text THEN '05'::text
            WHEN 'IM02'::text THEN '05'::text
            WHEN 'IM04'::text THEN '06'::text
            WHEN 'IM05'::text THEN '07'::text
            WHEN 'IM1011'::text THEN '08'::text
            WHEN 'IM10'::text THEN '08'::text
            WHEN 'IM11'::text THEN '08'::text
            WHEN 'BR01'::text THEN '09'::text
            WHEN 'BR10'::text THEN '10'::text
            WHEN 'BR07'::text THEN '11'::text
            WHEN 'BE045'::text THEN '12'::text
            WHEN 'BE04'::text THEN '12'::text
            WHEN 'BE05'::text THEN '12'::text
            WHEN 'BR045'::text THEN '13'::text
            WHEN 'BR04'::text THEN '13'::text
            WHEN 'BR05'::text THEN '13'::text
            WHEN 'BR039'::text THEN '14'::text
            WHEN 'BR03'::text THEN '14'::text
            WHEN 'BR09'::text THEN '14'::text
            WHEN 'IM078'::text THEN '15'::text
            WHEN 'IM07'::text THEN '15'::text
            WHEN 'IM08'::text THEN '15'::text
            WHEN 'IN10'::text THEN '16'::text
            WHEN 'IN13'::text THEN '17'::text
            WHEN 'IN023'::text THEN '18'::text
            WHEN 'IN02'::text THEN '18'::text
            WHEN 'IN03'::text THEN '18'::text
            WHEN 'IN14'::text THEN '19'::text
            WHEN 'IN16'::text THEN '20'::text
            WHEN 'IN15'::text THEN '21'::text
            WHEN 'IN0789'::text THEN '22'::text
            WHEN 'IN07'::text THEN '22'::text
            WHEN 'IN08'::text THEN '22'::text
            WHEN 'IN09'::text THEN '22'::text
            WHEN 'IN12'::text THEN '23'::text
            WHEN 'IN20'::text THEN '24'::text
            WHEN 'IN11'::text THEN '25'::text
            WHEN 'IN01'::text THEN '26'::text
            WHEN 'IN0456'::text THEN '27'::text
            WHEN 'IN04'::text THEN '27'::text
            WHEN 'IN05'::text THEN '27'::text
            WHEN 'IN06'::text THEN '27'::text
            WHEN 'GGOR'::text THEN '28'::text
            WHEN 'IN17'::text THEN '29'::text
            WHEN 'IN19_IM09'::text THEN '30'::text
            WHEN 'IN19'::text THEN '30'::text
            WHEN 'IM09'::text THEN '30'::text
            WHEN 'BE023'::text THEN '31'::text
            WHEN 'BE02'::text THEN '31'::text
            WHEN 'BE03'::text THEN '31'::text
            WHEN 'BE01'::text THEN '32'::text
            WHEN 'BE08'::text THEN '33'::text
            WHEN 'RO0123456'::text THEN '34'::text
            WHEN 'RO01'::text THEN '34'::text
            WHEN 'RO02'::text THEN '34'::text
            WHEN 'RO03'::text THEN '34'::text
            WHEN 'RO04'::text THEN '34'::text
            WHEN 'RO05'::text THEN '34'::text
            WHEN 'RO06'::text THEN '34'::text
            WHEN 'S05'::text THEN '35'::text
            WHEN 'S02'::text THEN '36'::text
            WHEN 'IN18'::text THEN '37'::text
            WHEN 'S04'::text THEN '38'::text
            WHEN 'S06'::text THEN '39'::text
            WHEN 'BE07'::text THEN '40'::text
            WHEN 'BE06'::text THEN '41'::text
            WHEN 'S03'::text THEN '42'::text
            WHEN 'S01'::text THEN '43'::text
            WHEN 'WB21'::text THEN '55'::text
            ELSE NULL::text
        END AS volgorde
   FROM sw_supp_measure_eu_type smeu
  ORDER BY
        CASE smeu.code_sgbp
            WHEN 'RO078'::text THEN '01'::text
            WHEN 'RO07'::text THEN '01'::text
            WHEN 'RO08'::text THEN '01'::text
            WHEN 'IM06'::text THEN '02'::text
            WHEN 'IM03'::text THEN '03'::text
            WHEN 'IM12'::text THEN '04'::text
            WHEN 'IM012'::text THEN '05'::text
            WHEN 'IM01'::text THEN '05'::text
            WHEN 'IM02'::text THEN '05'::text
            WHEN 'IM04'::text THEN '06'::text
            WHEN 'IM05'::text THEN '07'::text
            WHEN 'IM1011'::text THEN '08'::text
            WHEN 'IM10'::text THEN '08'::text
            WHEN 'IM11'::text THEN '08'::text
            WHEN 'BR01'::text THEN '09'::text
            WHEN 'BR10'::text THEN '10'::text
            WHEN 'BR07'::text THEN '11'::text
            WHEN 'BE045'::text THEN '12'::text
            WHEN 'BE04'::text THEN '12'::text
            WHEN 'BE05'::text THEN '12'::text
            WHEN 'BR045'::text THEN '13'::text
            WHEN 'BR04'::text THEN '13'::text
            WHEN 'BR05'::text THEN '13'::text
            WHEN 'BR039'::text THEN '14'::text
            WHEN 'BR03'::text THEN '14'::text
            WHEN 'BR09'::text THEN '14'::text
            WHEN 'IM078'::text THEN '15'::text
            WHEN 'IM07'::text THEN '15'::text
            WHEN 'IM08'::text THEN '15'::text
            WHEN 'IN10'::text THEN '16'::text
            WHEN 'IN13'::text THEN '17'::text
            WHEN 'IN023'::text THEN '18'::text
            WHEN 'IN02'::text THEN '18'::text
            WHEN 'IN03'::text THEN '18'::text
            WHEN 'IN14'::text THEN '19'::text
            WHEN 'IN16'::text THEN '20'::text
            WHEN 'IN15'::text THEN '21'::text
            WHEN 'IN0789'::text THEN '22'::text
            WHEN 'IN07'::text THEN '22'::text
            WHEN 'IN08'::text THEN '22'::text
            WHEN 'IN09'::text THEN '22'::text
            WHEN 'IN12'::text THEN '23'::text
            WHEN 'IN20'::text THEN '24'::text
            WHEN 'IN11'::text THEN '25'::text
            WHEN 'IN01'::text THEN '26'::text
            WHEN 'IN0456'::text THEN '27'::text
            WHEN 'IN04'::text THEN '27'::text
            WHEN 'IN05'::text THEN '27'::text
            WHEN 'IN06'::text THEN '27'::text
            WHEN 'GGOR'::text THEN '28'::text
            WHEN 'IN17'::text THEN '29'::text
            WHEN 'IN19_IM09'::text THEN '30'::text
            WHEN 'IN19'::text THEN '30'::text
            WHEN 'IM09'::text THEN '30'::text
            WHEN 'BE023'::text THEN '31'::text
            WHEN 'BE02'::text THEN '31'::text
            WHEN 'BE03'::text THEN '31'::text
            WHEN 'BE01'::text THEN '32'::text
            WHEN 'BE08'::text THEN '33'::text
            WHEN 'RO0123456'::text THEN '34'::text
            WHEN 'RO01'::text THEN '34'::text
            WHEN 'RO02'::text THEN '34'::text
            WHEN 'RO03'::text THEN '34'::text
            WHEN 'RO04'::text THEN '34'::text
            WHEN 'RO05'::text THEN '34'::text
            WHEN 'RO06'::text THEN '34'::text
            WHEN 'S05'::text THEN '35'::text
            WHEN 'S02'::text THEN '36'::text
            WHEN 'IN18'::text THEN '37'::text
            WHEN 'S04'::text THEN '38'::text
            WHEN 'S06'::text THEN '39'::text
            WHEN 'BE07'::text THEN '40'::text
            WHEN 'BE06'::text THEN '41'::text
            WHEN 'S03'::text THEN '42'::text
            WHEN 'S01'::text THEN '43'::text
            WHEN 'WB21'::text THEN '55'::text
            ELSE NULL::text
        END;


--
-- Name: vw_maatregelen_voortgang; Type: VIEW; Schema: public; Owner: -
--

CREATE VIEW vw_maatregelen_voortgang AS
 SELECT vw_maatregelen."DB_ID" AS "Maatregel_DB_ID",
    vw_maatregelen."Identifcatie" AS "Maatregel_Identificatie",
    vw_maatregelen."Naam" AS "Maatregel_Naam",
    measure_progress.reason_substanstial_delay AS "Motivering",
    measure_progress.amount_value AS "Hoeveelheid",
    measure_progress.year AS "Jaar",
    measure_status_type.code AS "VoortgangStatus_Code",
    measure_status_type.omschrijving
   FROM measure_progress,
    vw_maatregelen,
    measure_status_type
  WHERE ((vw_maatregelen."DB_ID" = measure_progress.mtm_id) AND (measure_status_type.mst_id = measure_progress.mst_id));


--
-- Name: vw_maatregelen_with_voortgang_for_download; Type: VIEW; Schema: public; Owner: -
--

CREATE VIEW vw_maatregelen_with_voortgang_for_download AS
 SELECT mtm.mtm_id AS "DB_ID",
    ('NL'::text || (wb_nst.code)::text) AS "Namespace",
    wb_nst.descrption AS "Waterbeheerder_Naam",
    regexp_replace((supp_add_measure_type.local_id)::text, '\r|\n'::text, ''::text, 'g'::text) AS "LokaalID",
    regexp_replace((supp_add_measure_type.measure_name)::text, '\r|\n'::text, ''::text, 'g'::text) AS "Naam",
    rpp.description AS "SGBPPeriode_Omschrijving",
    ((date_part('year'::text, reporting_period.period_start) || '-'::text) || date_part('year'::text, reporting_period.period_end)) AS "UitvoeringIn",
    regexp_replace((sw_supp_measure_eu_type.code)::text, '\r|\n'::text, ''::text, 'g'::text) AS "KRWmaatregel_Code",
    sw_supp_measure_eu_type.name AS "KRWmaatregel_Naam",
    regexp_replace((supp_add_measure_type.measure_description)::text, '\r|\n'::text, ''::text, 'g'::text) AS "Voortgang_Toelichting",
    sw_supp_measure_eu_type.hoofdcategorie AS "Hoofdcategorie",
    sw_supp_measure_eu_type.index AS "Index",
    sw_supp_measure_eu_type.klasse AS "SGBP_Klasse",
    sw_supp_measure_eu_type.harmonisatie AS "SGBP_Harmonisatie",
    sw_supp_measure_eu_type.code_sgbp AS "SGBP_code",
    sw_supp_measure_eu_type.artikel_sgbp AS "SGBP_artikel",
    sw_supp_measure_eu_type.tablkop_sgbp AS "SGBP_Hoofdcategorie",
    regexp_replace((level_of_area_type.code)::text, '\r|\n'::text, ''::text, 'g'::text) AS "KRWMaatregelNiveau_Code",
    regexp_replace((level_of_area_type.description)::text, '\r|\n'::text, ''::text, 'g'::text) AS "KRWMaatregelNiveau_Omschrijving",
    array_to_string(ARRAY( SELECT DISTINCT regexp_replace((ho.inspire_id_local_id)::text, '\r|\n'::text, ''::text, 'g'::text) AS regexp_replace
           FROM (hydro_object ho
             JOIN measure_per_man_reg_or_restr_zone mz ON ((mz.mrz_id = ho.hdo_id)))
          WHERE (mz.mtm_id = mtm.mtm_id)), '|'::text) AS "HoortbijKRWwaterlichaam",
    stroomgebieddistrict.inspire_id_local_id AS "KRWstroomgebiedDistrict_Code",
    supp_add_measure_type.is_additional_measure AS "OpnameInSGBPJN",
    regexp_replace((organisation_category_type.code)::text, '\r|\n'::text, ''::text, 'g'::text) AS "Initiatiefnemer_Code",
    regexp_replace(supp_add_measure_type.initiative_party, '\r|\n'::text, ''::text, 'g'::text) AS "Initiatiefnemer_Naam",
    array_to_string(ARRAY( SELECT DISTINCT regexp_replace((t.code)::text, '\r|\n'::text, ''::text, 'g'::text) AS regexp_replace
           FROM (monitored_measure_eu_fund m
             JOIN eu_fund_type t ON ((t.euf_id = m.euf_id)))
          WHERE (m.mtm_id = mtm.mtm_id)), '|'::text) AS "EUFonds_Code",
    array_to_string(ARRAY( SELECT DISTINCT regexp_replace((vbg."Identificatie")::text, '\r|\n'::text, ''::text, 'g'::text) AS regexp_replace
           FROM (vw_beschermdegebieden vbg
             JOIN measure_per_man_protected_area mpmpa ON ((mpmpa.wpa_id = vbg."DB_ID")))
          WHERE ((mpmpa.mtm_id = mtm.mtm_id) AND (vbg."Versie_ID" = river_basin_management_plan.wkrv_id))), '|'::text) AS "RelatieMetNatura2000Gebied",
    array_to_string(ARRAY( SELECT DISTINCT regexp_replace((vgo."Identificatie")::text, '\r|\n'::text, ''::text, 'g'::text) AS regexp_replace
           FROM (vw_gw_onttrekking vgo
             JOIN measure_per_abstraction_point mpap ON ((mpap.asp_id = vgo."DB_ID")))
          WHERE ((mpap.mtm_id = mtm.mtm_id) AND (vgo.wkr_versie = river_basin_management_plan.wkrv_id))), '|'::text) AS "RelatieMetWaterwinning",
    array_to_string(ARRAY( SELECT DISTINCT regexp_replace((((mft.omschrijving)::text || '='::text) || mf2.sum), '\r|\n'::text, ''::text, 'g'::text) AS regexp_replace
           FROM (measure_finance mf2
             JOIN measure_finance_type mft ON ((mft.mtf_id = mf2.mft_id)))
          WHERE ((mf2.mtm_id = mtm.mtm_id) AND (mf2.mft_id <> 3))), '|'::text) AS kosten,
    river_basin_management_plan.wkrv_id AS versie,
    (''::text || supp_add_measure_type.amount_value) AS "OmvangNumeriekeWaarde",
    regexp_replace((eenheid_type.code)::text, '\r|\n'::text, ''::text, 'g'::text) AS omvangeenheidcode,
    (''::text || mp1.amount_value) AS "Plan",
    (''::text || mp2.amount_value) AS "Uitvoering",
    (''::text || mp3.amount_value) AS "Uitgevoerd",
    (''::text || mp4.amount_value) AS "Gefaseerd",
    (''::text || mp5.amount_value) AS "Vervangen",
    (''::text || mp6.amount_value) AS "Ingetrokken",
    mp1.year AS "Jaar_voortgang",
    ca.ore_id AS waterbeheerderoreid,
    mp1.year AS year1,
    mp2.year AS year2,
    mp3.year AS year3,
    mp4.year AS year4,
    mp5.year AS year5,
    mp6.year AS year6,
    supp_add_measure_type.process_info
   FROM (((((((((((((((((((((((((competent_authority ca
     JOIN namespace_type nst ON ((ca.namespace_id = nst.ns_id)))
     JOIN competentauthority_namespacetype cans ON ((cans.ore_id = ca.ore_id)))
     JOIN hydro_object hdo ON ((cans.ns_id = hdo.inspire_id_namespace)))
     JOIN measure_per_man_reg_or_restr_zone mpmr ON ((hdo.hdo_id = mpmr.mrz_id)))
     JOIN monitored_measure mtm ON ((mpmr.mtm_id = mtm.mtm_id)))
     JOIN supp_add_measure_type ON ((supp_add_measure_type.smnl_id = mtm.mtm_id)))
     JOIN sw_supp_measure_eu_type ON ((sw_supp_measure_eu_type.smeu_id = supp_add_measure_type.smeu_id)))
     JOIN eenheid_type ON ((eenheid_type.eenh_id = sw_supp_measure_eu_type.eenh_id)))
     JOIN namespace_type wb_nst ON ((wb_nst.ns_id = supp_add_measure_type.namespace_id)))
     JOIN competentauthority_namespacetype ON ((competentauthority_namespacetype.ns_id = wb_nst.ns_id)))
     JOIN competent_authority ON ((competent_authority.ore_id = competentauthority_namespacetype.ore_id)))
     JOIN report_version ON ((report_version.rpv_id = mtm.rpv_id)))
     JOIN reporting_period ON ((reporting_period.rpp_id = report_version.rpp_id)))
     JOIN level_of_area_type ON ((level_of_area_type.loa_id = mtm.level_of_measure_id)))
     JOIN organisation_category_type ON ((organisation_category_type.ocat_id = supp_add_measure_type.initiative_party_ocat_id)))
     JOIN river_basin_management_plan ON ((river_basin_management_plan.rbmp_id = supp_add_measure_type.rbmp_id)))
     JOIN hydro_object stroomgebieddistrict ON ((stroomgebieddistrict.hdo_id = river_basin_management_plan.rbd_id)))
     JOIN report_version rv2 ON ((rv2.wkrv_id = river_basin_management_plan.wkrv_id)))
     JOIN reporting_period rpp ON (((rpp.rpp_id = rv2.rpp_id) AND (rv2.begin_lifespan_version <= now()) AND ((rv2.end_lifespan_version > now()) OR (rv2.end_lifespan_version IS NULL)) AND (rpp.leg_ref_id = 1))))
     LEFT JOIN measure_progress mp1 ON (((supp_add_measure_type.smnl_id = mp1.mtm_id) AND (mp1.mst_id = 1) AND (mp1.year = 2015))))
     LEFT JOIN measure_progress mp2 ON (((supp_add_measure_type.smnl_id = mp2.mtm_id) AND (mp2.mst_id = 2) AND (mp2.year = 2015))))
     LEFT JOIN measure_progress mp3 ON (((supp_add_measure_type.smnl_id = mp3.mtm_id) AND (mp3.mst_id = 3) AND (mp3.year = 2015))))
     LEFT JOIN measure_progress mp4 ON (((supp_add_measure_type.smnl_id = mp4.mtm_id) AND (mp4.mst_id = 4) AND (mp4.year = 2015))))
     LEFT JOIN measure_progress mp5 ON (((supp_add_measure_type.smnl_id = mp5.mtm_id) AND (mp5.mst_id = 5) AND (mp5.year = 2015))))
     LEFT JOIN measure_progress mp6 ON (((supp_add_measure_type.smnl_id = mp6.mtm_id) AND (mp6.mst_id = 6) AND (mp6.year = 2015))))
  GROUP BY mtm.mtm_id, wb_nst.code, wb_nst.descrption, supp_add_measure_type.local_id, supp_add_measure_type.measure_name, rpp.description, reporting_period.period_start, reporting_period.period_end, sw_supp_measure_eu_type.code, sw_supp_measure_eu_type.name, supp_add_measure_type.measure_description, sw_supp_measure_eu_type.hoofdcategorie, sw_supp_measure_eu_type.index, sw_supp_measure_eu_type.klasse, sw_supp_measure_eu_type.harmonisatie, sw_supp_measure_eu_type.code_sgbp, sw_supp_measure_eu_type.artikel_sgbp, sw_supp_measure_eu_type.tablkop_sgbp, level_of_area_type.code, level_of_area_type.description, stroomgebieddistrict.inspire_id_local_id, supp_add_measure_type.is_additional_measure, organisation_category_type.code, supp_add_measure_type.initiative_party, river_basin_management_plan.wkrv_id, supp_add_measure_type.amount_value, eenheid_type.code, mp1.amount_value, mp2.amount_value, mp3.amount_value, mp4.amount_value, mp5.amount_value, mp6.amount_value, mp1.year, ca.ore_id, mp2.year, mp3.year, mp4.year, mp5.year, mp6.year, supp_add_measure_type.process_info
  ORDER BY supp_add_measure_type.local_id;


--
-- Name: vw_match_opts_taxa_G_met_I; Type: VIEW; Schema: public; Owner: -
--

CREATE VIEW "vw_match_opts_taxa_G_met_I" AS
 SELECT optg.opt_id AS "optG.opt_id",
    optg.observed_property_type_class AS "optG.observed_property_type_class",
    optg.result_type AS "optG.result_type",
    optg.hoedanigheid_id AS "optG.hoedanigheid_id",
    optg.object_group_id AS "optG.object_group_id",
    optg.quantity_id AS "optG.quantity_id",
    optg.taxa_group_id AS "optG.taxa_group_id",
    optg.substance_group_id AS "optG.substance_group_id",
    optg.indicator_id AS "optG.indicator_id",
    optg.classification_group_id AS "optG.classification_group_id",
    optg.remarks AS "optG.remarks",
    optg.d_begin AS "optG.d_begin",
    optg.d_eind AS "optG.d_eind",
    optg.last_changed_date AS "optG.last_changed_date",
    optg.d_status AS "optG.d_status",
    hdhg.hdh_id AS "hdhG.hdh_id",
    hdhg.code AS "hdhG.code",
    hdhg.omschrijving AS "hdhG.omschrijving",
    hdhg.d_begin AS "hdhG.d_begin",
    hdhg.d_eind AS "hdhG.d_eind",
    hdhg.last_changed_date AS "hdhG.last_changed_date",
    hdhg.d_status AS "hdhG.d_status",
    hdhg.id AS "hdhG.id",
    grhg.grh_id AS "grhG.grh_id",
    grhg.code AS "grhG.code",
    grhg.omschrijving AS "grhG.omschrijving",
    grhg.d_begin AS "grhG.d_begin",
    grhg.d_eind AS "grhG.d_eind",
    grhg.last_changed_date AS "grhG.last_changed_date",
    grhg.d_status AS "grhG.d_status",
    grhg.id AS "grhG.id",
    tgeg.txg_id AS "tgeG.txg_id",
    tgeg.txn_id AS "tgeG.txn_id",
    txgg.txg_id AS "txgG.txg_id",
    txgg.name AS "txgG.name",
    txgg.group_type AS "txgG.group_type",
    txgg.d_begin AS "txgG.d_begin",
    txgg.d_eind AS "txgG.d_eind",
    txgg.last_changed_date AS "txgG.last_changed_date",
    txgg.d_status AS "txgG.d_status",
    tgei.txg_id AS "tgeI.txg_id",
    tgei.txn_id AS "tgeI.txn_id",
    txgi.txg_id AS "txgI.txg_id",
    txgi.name AS "txgI.name",
    txgi.group_type AS "txgI.group_type",
    txgi.d_begin AS "txgI.d_begin",
    txgi.d_eind AS "txgI.d_eind",
    txgi.last_changed_date AS "txgI.last_changed_date",
    txgi.d_status AS "txgI.d_status",
    opti.opt_id AS "optI.opt_id",
    opti.observed_property_type_class AS "optI.observed_property_type_class",
    opti.result_type AS "optI.result_type",
    opti.hoedanigheid_id AS "optI.hoedanigheid_id",
    opti.object_group_id AS "optI.object_group_id",
    opti.quantity_id AS "optI.quantity_id",
    opti.taxa_group_id AS "optI.taxa_group_id",
    opti.substance_group_id AS "optI.substance_group_id",
    opti.indicator_id AS "optI.indicator_id",
    opti.classification_group_id AS "optI.classification_group_id",
    opti.remarks AS "optI.remarks",
    opti.d_begin AS "optI.d_begin",
    opti.d_eind AS "optI.d_eind",
    opti.last_changed_date AS "optI.last_changed_date",
    opti.d_status AS "optI.d_status",
    hdhi.hdh_id AS "hdhI.hdh_id",
    hdhi.code AS "hdhI.code",
    hdhi.omschrijving AS "hdhI.omschrijving",
    hdhi.d_begin AS "hdhI.d_begin",
    hdhi.d_eind AS "hdhI.d_eind",
    hdhi.last_changed_date AS "hdhI.last_changed_date",
    hdhi.d_status AS "hdhI.d_status",
    hdhi.id AS "hdhI.id",
    grhi.grh_id AS "grhI.grh_id",
    grhi.code AS "grhI.code",
    grhi.omschrijving AS "grhI.omschrijving",
    grhi.d_begin AS "grhI.d_begin",
    grhi.d_eind AS "grhI.d_eind",
    grhi.last_changed_date AS "grhI.last_changed_date",
    grhi.d_status AS "grhI.d_status",
    grhi.id AS "grhI.id"
   FROM (((((((((( SELECT txg.txg_id,
            txg.name,
            txg.group_type,
            txg.d_begin,
            txg.d_eind,
            txg.last_changed_date,
            txg.d_status
           FROM taxa_group txg
          WHERE ((txg.group_type)::text = 'G'::text)) txgg
     LEFT JOIN observed_property_type optg ON ((optg.taxa_group_id = txgg.txg_id)))
     LEFT JOIN hoedanigheid_type hdhg ON ((hdhg.hdh_id = optg.hoedanigheid_id)))
     LEFT JOIN grootheid_type grhg ON ((grhg.grh_id = optg.quantity_id)))
     LEFT JOIN taxa_group_element tgeg ON ((tgeg.txg_id = txgg.txg_id)))
     LEFT JOIN taxa_group_element tgei ON (((tgei.txn_id = tgeg.txn_id) AND (tgei.txg_id <> tgeg.txg_id))))
     LEFT JOIN taxa_group txgi ON (((txgi.txg_id = tgei.txg_id) AND ((txgi.group_type)::text = 'I'::text))))
     LEFT JOIN observed_property_type opti ON (((opti.taxa_group_id = txgi.txg_id) AND (((opti.quantity_id IS NULL) AND (optg.quantity_id IS NULL)) OR (opti.quantity_id = optg.quantity_id)) AND (((opti.hoedanigheid_id IS NULL) AND (optg.hoedanigheid_id IS NULL)) OR (opti.hoedanigheid_id = optg.hoedanigheid_id)))))
     LEFT JOIN hoedanigheid_type hdhi ON ((hdhi.hdh_id = opti.hoedanigheid_id)))
     LEFT JOIN grootheid_type grhi ON ((grhi.grh_id = opti.quantity_id)));


--
-- Name: vw_meetlocatie_waterlichaam; Type: VIEW; Schema: public; Owner: -
--

CREATE VIEW vw_meetlocatie_waterlichaam AS
 SELECT mno.inspire_id_local_id AS "Meetpunt.identificatie",
    mno.name AS "Meetpunt.omschrijving",
    st_x(st_transform(mno.geometry, 28992)) AS "Geometriepunt.X_RD",
    st_y(st_transform(mno.geometry, 28992)) AS "Geometriepunt.Y_RD",
    hdo.inspire_id_local_id AS "Waterlichaam.identificatie",
    wln.omschrijving AS "Waterlichaam.omschrijving",
    ns.code AS "Waterbeheerder.code",
    ns.descrption AS "Waterbeheerder.omschrijving",
    wln.stroomgebieddistrict AS "Stroomgebieddistrict.code",
    mno.wkrv_id AS "Versie.code",
    mno.last_change_time
   FROM ((((((((monitoring_object mno
     JOIN wkr_version wkrv ON ((wkrv.wkrv_id = mno.wkrv_id)))
     JOIN monitoring_feature mnf ON ((mnf.mnf_id = mno.mno_id)))
     JOIN environmental_monitoring_facility emf ON ((emf.emf_id = mnf.mnf_id)))
     JOIN management_regulation_or_restriction_zone mrz ON ((mrz.mrz_id = emf.ligt_in_mrz_id)))
     JOIN water_body wbd ON ((wbd.wbd_id = mrz.mrz_id)))
     JOIN hydro_object hdo ON ((hdo.hdo_id = mrz.mrz_id)))
     JOIN vw_waterlichamen wln ON ((wln.db_id = hdo.hdo_id)))
     JOIN namespace_type ns ON ((ns.ns_id = mno.inspire_id_namespace_id)))
  WHERE (st_geometrytype(mno.geometry) = 'ST_Point'::text)
  ORDER BY wln.waterbeheerder_code, hdo.inspire_id_local_id;


--
-- Name: vw_meetpunt_meetnet_csv; Type: VIEW; Schema: public; Owner: -
--

CREATE VIEW vw_meetpunt_meetnet_csv AS
 SELECT mpc.meetpunt_identificatie_db_id,
    mpc."Meetpunt.identificatie",
    mpc."Meetpunt.omschrijving",
    mpc."GeometriePunt.X_RD",
    mpc."GeometriePunt.Y_RD",
    mpc."Waterbeheerder.code",
    mpc."Waterbeheerder.omschrijving",
    mmp."Meetnet_Identificatie" AS "Meetnet.identificatie",
    mmp."Meetnet_Omschrijving" AS "Meetnet.omschrijving",
    mmp.wkr_versie AS "Versie"
   FROM (aquo_formaten.vw_umaquo_meetpunten_csv mpc
     JOIN vw_meetnet_meetpunt_g mmp ON (((mmp."Meetpunt_Identificatie")::text = (mpc."Meetpunt.identificatie")::text)))
  ORDER BY mpc."Waterbeheerder.code", mpc."Meetpunt.identificatie";


--
-- Name: vw_meetpunten_cml_csv; Type: VIEW; Schema: public; Owner: -
--

CREATE VIEW vw_meetpunten_cml_csv AS
 SELECT monitoring_object.inspire_id_local_id AS "Meetpunt.identificatie",
    monitoring_object.name AS "Meetpunt.omschrijving",
    namespace_type.code AS "Waterbeheerder.code",
    namespace_type.descrption AS "Waterbeheerder.omschrijving",
    st_x(st_transform(monitoring_object.geometry, 28992)) AS "GeometriePunt.X_RD",
    st_y(st_transform(monitoring_object.geometry, 28992)) AS "GeometriePunt.Y_RD",
    monitoring_object.mno_id AS meetpunt_identificatie_db_id,
    monitoring_object.wkrv_id,
    monitoring_object.last_change_time
   FROM (((monitoring_object
     JOIN monitored_compartiment ON ((monitored_compartiment.mno_id = monitoring_object.mno_id)))
     JOIN namespace_type ON ((namespace_type.ns_id = monitoring_object.inspire_id_namespace_id)))
     JOIN monitoring_feature ON ((monitoring_feature.mnf_id = monitoring_object.mno_id)))
  WHERE (st_geometrytype(monitoring_object.geometry) = 'ST_Point'::text)
  ORDER BY namespace_type.code, monitoring_object.inspire_id_local_id;


--
-- Name: vw_meetpunten_csv; Type: VIEW; Schema: public; Owner: -
--

CREATE VIEW vw_meetpunten_csv AS
 SELECT monitoring_object.mno_id AS meetpunt_identificatie_db_id,
    monitoring_object.inspire_id_local_id AS "Meetpunt.identificatie",
    monitoring_object.name AS "Meetpunt.omschrijving",
    namespace_type.code AS "Waterbeheerder.code",
    namespace_type.descrption AS "Waterbeheerder.omschrijving",
    st_x(st_transform(monitoring_object.geometry, 28992)) AS "GeometriePunt.X_RD",
    st_y(st_transform(monitoring_object.geometry, 28992)) AS "GeometriePunt.Y_RD",
    monitoring_object.wkrv_id,
    monitoring_object.last_change_time
   FROM (((monitoring_object
     JOIN monitored_compartiment ON ((monitored_compartiment.mno_id = monitoring_object.mno_id)))
     JOIN namespace_type ON ((namespace_type.ns_id = monitoring_object.inspire_id_namespace_id)))
     JOIN monitoring_feature ON ((monitoring_feature.mnf_id = monitoring_object.mno_id)))
  WHERE (st_geometrytype(monitoring_object.geometry) = 'ST_Point'::text)
  ORDER BY namespace_type.code, monitoring_object.inspire_id_local_id;


--
-- Name: VIEW vw_meetpunten_csv; Type: COMMENT; Schema: public; Owner: -
--

COMMENT ON VIEW vw_meetpunten_csv IS 'Deze view laat de meetpunten zien zoals ze zijn ingelezen via de landelijke enquete waterkwaliteit. De laatste versie is versie 14';


--
-- Name: vw_meetpunten_shape; Type: VIEW; Schema: public; Owner: -
--

CREATE VIEW vw_meetpunten_shape AS
 SELECT DISTINCT ON (monitoring_object.inspire_id_local_id) monitoring_object.inspire_id_local_id AS "IDENT",
    namespace_type.code AS "WBHCODE",
    namespace_type.descrption AS "WBHNAAM",
    monitoring_object.name AS "MPNNAAM",
    monitoring_object.additional_description AS "TOELICHT",
    monitoring_object.geometry,
    monitoring_feature.pos_accuracy_horizontal_value AS "PRECISIE",
    eenheid_type.code AS "PREC_EEN",
    measurement_regime_type.description AS "REGIME",
    environmental_monitoring_facility.is_mobile AS "ISMOBIEL",
    result_acquisition_source_type.description AS "INWINSRT",
    specialised_emf_type.description AS "TYPESRT",
    subsite_type.description AS "LOCTYPE",
    monitoring_station.number_of_points_in_subsite AS "AANTPNT",
    management_regulation_or_restriction_zone.mrz_id AS "IN_OWM"
   FROM ((((((wkr_version
     RIGHT JOIN (namespace_type
     RIGHT JOIN (monitoring_object
     RIGHT JOIN (((hydro_object
     JOIN management_regulation_or_restriction_zone ON ((hydro_object.hdo_id = management_regulation_or_restriction_zone.mrz_id)))
     JOIN namespace_type namespace_type_1 ON ((hydro_object.inspire_id_namespace = namespace_type_1.ns_id)))
     RIGHT JOIN (environmental_monitoring_facility
     JOIN monitoring_feature ON ((environmental_monitoring_facility.emf_id = monitoring_feature.mnf_id))) ON ((management_regulation_or_restriction_zone.mrz_id = environmental_monitoring_facility.ligt_in_mrz_id))) ON ((monitoring_object.mno_id = monitoring_feature.mnf_id))) ON ((namespace_type.ns_id = monitoring_object.inspire_id_namespace_id))) ON ((wkr_version.wkrv_id = monitoring_object.wkrv_id)))
     LEFT JOIN eenheid_type ON ((monitoring_feature.pos_accuracy_horizontal_uom_id = eenheid_type.eenh_id)))
     LEFT JOIN specialised_emf_type ON ((environmental_monitoring_facility.speciallised_emf_type_id = specialised_emf_type.semf_id)))
     LEFT JOIN result_acquisition_source_type ON ((environmental_monitoring_facility.result_acquisition_source_id = result_acquisition_source_type.ras_id)))
     LEFT JOIN measurement_regime_type ON ((environmental_monitoring_facility.measurement_regime_id = measurement_regime_type.mmr_id)))
     LEFT JOIN (subsite_type
     RIGHT JOIN monitoring_station ON ((subsite_type.sst_id = monitoring_station.subsite_type_id))) ON ((environmental_monitoring_facility.emf_id = monitoring_station.mts_id)))
  WHERE (st_geometrytype(monitoring_object.geometry) = 'ST_Point'::text)
  ORDER BY monitoring_object.inspire_id_local_id, monitoring_object.wkrv_id DESC;


--
-- Name: vw_milieudoelstellingen_art43a_owm; Type: VIEW; Schema: public; Owner: -
--

CREATE VIEW vw_milieudoelstellingen_art43a_owm AS
 SELECT swb_measures_43a.swee_id AS "DB_ID",
    hdo_swb.hdo_id AS "Waterlichaam_DB_ID",
    hdo_swb.inspire_id_local_id AS "Waterlichaam_Identificatie",
    eu_function_43a_type.fu43_id AS "Functie_DB_ID",
    eu_function_43a_type.function AS "Functie_Omschrijving",
    sw_measure43_nl_type.me43_id AS "Maatregel_NietGenomen_DB_ID",
    sw_measure43_nl_type.omschrijving AS "Maatregel_NietGenomen_Omschrijving",
    swb_measures_43a.motivation AS "Motivatie",
    surface_water_body.article_43_comment AS "Toelichting",
    surface_water_body.article_43_litref AS "Literatuur"
   FROM (((((swb_measures_43a
     LEFT JOIN hydro_object hdo_swb ON ((hdo_swb.hdo_id = swb_measures_43a.swb_id)))
     LEFT JOIN surface_water_body ON ((surface_water_body.swb_id = hdo_swb.hdo_id)))
     LEFT JOIN sw_measure43_function ON ((swb_measures_43a.swee_id = sw_measure43_function.smee_id)))
     LEFT JOIN sw_measure43_nl_type ON ((sw_measure43_nl_type.me43_id = sw_measure43_function.me43_id)))
     LEFT JOIN eu_function_43a_type ON ((eu_function_43a_type.fu43_id = swb_measures_43a.fu43_id)))
  ORDER BY hdo_swb.inspire_id_local_id, sw_measure43_function.me43_id, sw_measure43_nl_type.me43_id;


--
-- Name: vw_milieudoelstellingen_art43a_owm_csv; Type: VIEW; Schema: public; Owner: -
--

CREATE VIEW vw_milieudoelstellingen_art43a_owm_csv AS
 SELECT hdo_swb.inspire_id_local_id AS "Oppervlaktewaterlichaam.Identificatie",
    eu_function_43a_type.function AS "Functie.Omschrijving",
    array_to_string(ARRAY( SELECT DISTINCT regexp_replace((sw_measure43_nl_type.omschrijving)::text, '\r|\n'::text, ''::text, 'g'::text) AS regexp_replace
           FROM (sw_measure43_nl_type
             LEFT JOIN sw_measure43_function ON ((sw_measure43_nl_type.me43_id = sw_measure43_function.me43_id)))
          WHERE (swb_measures_43a.swee_id = sw_measure43_function.smee_id)), '|'::text) AS "MaatregelNietGenomen",
    swb_measures_43a.motivation AS "Motivatie",
    hdo_swb.wkrv_id AS versie
   FROM (((swb_measures_43a
     LEFT JOIN hydro_object hdo_swb ON ((hdo_swb.hdo_id = swb_measures_43a.swb_id)))
     LEFT JOIN surface_water_body ON ((surface_water_body.swb_id = hdo_swb.hdo_id)))
     LEFT JOIN eu_function_43a_type ON ((eu_function_43a_type.fu43_id = swb_measures_43a.fu43_id)))
  ORDER BY hdo_swb.inspire_id_local_id;


--
-- Name: vw_milieudoelstellingen_art43b_owm; Type: VIEW; Schema: public; Owner: -
--

CREATE VIEW vw_milieudoelstellingen_art43b_owm AS
 SELECT hdo_swb.hdo_id AS "Waterlichaam_DB_ID",
    hdo_swb.inspire_id_local_id AS "Waterlichaam_Identificatie",
    eu_article_43b_type.a43b_id AS "Motiveringsgrond_DB_ID",
    eu_article_43b_type.omschrijving AS "Motiveringsgrond_Omschrijving",
    surface_water_body.article_43b_motivation AS "Motivering"
   FROM (((swb_art43b_excemption
     LEFT JOIN hydro_object hdo_swb ON ((hdo_swb.hdo_id = swb_art43b_excemption.swb_id)))
     LEFT JOIN surface_water_body ON ((surface_water_body.swb_id = hdo_swb.hdo_id)))
     LEFT JOIN eu_article_43b_type ON ((eu_article_43b_type.a43b_id = swb_art43b_excemption.a43b_id)))
  ORDER BY hdo_swb.inspire_id_local_id, eu_article_43b_type.a43b_id;


--
-- Name: vw_milieudoelstellingen_art43b_owm_csv; Type: VIEW; Schema: public; Owner: -
--

CREATE VIEW vw_milieudoelstellingen_art43b_owm_csv AS
 SELECT hdo_swb.inspire_id_local_id AS "Waterlichaam.Identificatie",
    eu_article_43b_type.omschrijving AS "Motiveringsgrond.Omschrijving",
    surface_water_body.article_43b_motivation AS "Motivering",
    hdo_swb.wkrv_id AS versie
   FROM (((swb_art43b_excemption
     LEFT JOIN hydro_object hdo_swb ON ((hdo_swb.hdo_id = swb_art43b_excemption.swb_id)))
     LEFT JOIN surface_water_body ON ((surface_water_body.swb_id = hdo_swb.hdo_id)))
     LEFT JOIN eu_article_43b_type ON ((eu_article_43b_type.a43b_id = swb_art43b_excemption.a43b_id)))
  ORDER BY hdo_swb.inspire_id_local_id, eu_article_43b_type.a43b_id;


--
-- Name: vw_milieudoelstellingen_art44_owm; Type: VIEW; Schema: public; Owner: -
--

CREATE VIEW vw_milieudoelstellingen_art44_owm AS
 SELECT swb_exemption.swce_id AS "DB_ID",
    hdo_swb.hdo_id AS "Waterlichaam_DB_ID",
    hdo_swb.inspire_id_local_id AS "Waterlichaam_Identificatie",
    objectives_exemption_type.obex_id AS "Motiveringsgrond_DB_ID",
    objectives_exemption_type.name AS "Motiveringsgrond",
    excemption_mechanism_type.exme_id AS "Mechanisme_DB_ID",
    excemption_mechanism_type.omschrijving AS "Mechanisme",
    swb_exemption.comment AS "Motivatie"
   FROM ((((swb_exemption
     LEFT JOIN objectives_exemption_type ON ((objectives_exemption_type.obex_id = swb_exemption.obex_id)))
     LEFT JOIN hydro_object hdo_swb ON ((hdo_swb.hdo_id = swb_exemption.swb_id)))
     LEFT JOIN swb_excemption_mechanism_44 ON ((swb_excemption_mechanism_44.swce_id = swb_exemption.swce_id)))
     LEFT JOIN excemption_mechanism_type ON ((excemption_mechanism_type.exme_id = swb_excemption_mechanism_44.exme_id)))
  WHERE ((objectives_exemption_type.article_nr)::text = '4.4'::text);


--
-- Name: vw_milieudoelstellingen_kwaliteitselement_ecologie_owm; Type: VIEW; Schema: public; Owner: -
--

CREATE VIEW vw_milieudoelstellingen_kwaliteitselement_ecologie_owm AS
 SELECT swb_exemption.swce_id AS "DB_ID",
    hdo_swb.hdo_id AS "Waterlichaam_DB_ID",
    hdo_swb.inspire_id_local_id AS "Waterlichaam_Identificatie",
    objectives_exemption_type.obex_id AS "Motiveringsgrond_DB_ID",
    objectives_exemption_type.name AS "Motiveringsgrond_Omschrijving",
    objectives_exemption_type.article_nr AS "Moviveringsgrond_Artikel",
    swb_exemption.comment AS "Motivering",
    vw_waargenomen_eigenschap."DB_ID" AS "Waargenomen_Eigenschap_DB_ID",
    vw_waargenomen_eigenschap."Tpering_Code",
    vw_waargenomen_eigenschap."Typering_Omschrijving",
    vw_waargenomen_eigenschap."Grootheid_Code",
    vw_waargenomen_eigenschap."Grootheid_Omschrijving",
    vw_waargenomen_eigenschap."ChemischeStof_code",
    vw_waargenomen_eigenschap."ChemischeStof_Omschrijving",
    vw_waargenomen_eigenschap."Hoedanigheid_Code",
    vw_waargenomen_eigenschap."Hoedanigheid_Omschrijving",
    NULL::integer AS "ChemischeStof_DB_ID"
   FROM ((((swb_exemption
     LEFT JOIN objectives_exemption_type ON ((objectives_exemption_type.obex_id = swb_exemption.obex_id)))
     LEFT JOIN swb_ecol_exemp_qe ON ((swb_ecol_exemp_qe.swce_id = swb_exemption.swce_id)))
     LEFT JOIN vw_waargenomen_eigenschap ON ((vw_waargenomen_eigenschap."DB_ID" = swb_ecol_exemp_qe.opt_id)))
     LEFT JOIN hydro_object hdo_swb ON ((hdo_swb.hdo_id = swb_exemption.swb_id)))
  ORDER BY hdo_swb.inspire_id_local_id, objectives_exemption_type.article_nr, objectives_exemption_type.obex_id, vw_waargenomen_eigenschap."Tpering_Code", vw_waargenomen_eigenschap."Grootheid_Code", vw_waargenomen_eigenschap."ChemischeStof_code";


--
-- Name: vw_milieudoelstellingen_kwaliteitselement_gwl; Type: VIEW; Schema: public; Owner: -
--

CREATE VIEW vw_milieudoelstellingen_kwaliteitselement_gwl AS
 SELECT gwb_chemical_exemption.gwce_id AS "DB_ID",
    hdo_gwb.hdo_id AS "Waterlichaam_DB_ID",
    hdo_gwb.inspire_id_local_id AS "Waterlichaam_Identificatie",
    objectives_exemption_type.obex_id AS "Motiveringsgrond_DB_ID",
    objectives_exemption_type.name AS "Motiveringsgrond_Omschrijving",
    objectives_exemption_type.article_nr AS "Moviveringsgrond_Artikel",
    gwb_chemical_exemption.comment AS "Motivering",
    wfd_qe_gwtype.name
   FROM ((((gwb_chemical_exemption
     LEFT JOIN objectives_exemption_type ON ((objectives_exemption_type.obex_id = gwb_chemical_exemption.obex_id)))
     LEFT JOIN gwb_chem_exemp_pollutant ON ((gwb_chem_exemp_pollutant.gwce_id = gwb_chemical_exemption.gwce_id)))
     LEFT JOIN wfd_qe_gwtype ON ((wfd_qe_gwtype.opt_id = gwb_chem_exemp_pollutant.opt_id)))
     LEFT JOIN hydro_object hdo_gwb ON ((hdo_gwb.hdo_id = gwb_chemical_exemption.gwb_id)));


--
-- Name: vw_milieudoelstellingen_prioritaire_stof_owm; Type: VIEW; Schema: public; Owner: -
--

CREATE VIEW vw_milieudoelstellingen_prioritaire_stof_owm AS
 SELECT swb_exemption.swce_id AS "DB_ID",
    hdo_swb.hdo_id AS "Waterlichaam_DB_ID",
    hdo_swb.inspire_id_local_id AS "Waterlichaam_Identificatie",
    objectives_exemption_type.obex_id AS "Motiveringsgrond_DB_ID",
    objectives_exemption_type.name AS "Motiveringsgrond_Omschrijving",
    objectives_exemption_type.article_nr AS "Moviveringsgrond_Artikel",
    swb_exemption.comment AS "Motivering",
    NULL::integer AS "Waargenomen_Eigenschap_DB_ID",
    NULL::text AS "Tpering_Code",
    NULL::text AS "Typering_Omschrijving",
    'CONCTTE'::text AS "Grootheid_Code",
    '(massa)Concentratie'::text AS "Grootheid_Omschrijving",
    chemische_stof_type.code AS "ChemischeStof_Code",
    chemische_stof_type.naam AS "ChemischeStof_Omschrijving",
    'NVT'::text AS "Hoedanigheid_Code",
    'Niet van toepassing'::text AS "Hoedanigheid_Omschrijving",
    chemische_stof_type.chs_id AS "ChemischeStof_DB_ID"
   FROM ((((swb_exemption
     LEFT JOIN objectives_exemption_type ON ((objectives_exemption_type.obex_id = swb_exemption.obex_id)))
     LEFT JOIN swb_chem_exemp_pollutant ON ((swb_chem_exemp_pollutant.swce_id = swb_exemption.swce_id)))
     LEFT JOIN chemische_stof_type ON ((chemische_stof_type.chs_id = swb_chem_exemp_pollutant.chs_id)))
     LEFT JOIN hydro_object hdo_swb ON ((hdo_swb.hdo_id = swb_exemption.swb_id)))
  WHERE (chemische_stof_type.chs_id IS NOT NULL)
  ORDER BY hdo_swb.inspire_id_local_id, objectives_exemption_type.article_nr, objectives_exemption_type.obex_id, chemische_stof_type.code;


--
-- Name: vw_milieudoelstellingen_art44_tm_art47_csv; Type: VIEW; Schema: public; Owner: -
--

CREATE VIEW vw_milieudoelstellingen_art44_tm_art47_csv AS
 SELECT hdo_swb.inspire_id_local_id AS "Waterlichaam.Identificatie",
    objectives_exemption_type.article_nr AS "Uitzondering.Artikel",
    objectives_exemption_type.name AS "Uitzonderingsgrond",
    array_to_string(ARRAY( SELECT DISTINCT regexp_replace((excemption_mechanism_type.omschrijving)::text, '\r|\n'::text, ''::text, 'g'::text) AS regexp_replace
           FROM (excemption_mechanism_type
             LEFT JOIN swb_excemption_mechanism_44 ON ((excemption_mechanism_type.exme_id = swb_excemption_mechanism_44.exme_id)))
          WHERE (swb_excemption_mechanism_44.swce_id = swb_exemption.swce_id)), '|'::text) AS "Artikel4-4.Mechanisme",
    swb_exemption.comment AS "Motivatie",
    array_to_string(ARRAY( SELECT DISTINCT regexp_replace((eco."Typering_Omschrijving")::text, '\r|\n'::text, ''::text, 'g'::text) AS regexp_replace
           FROM vw_milieudoelstellingen_kwaliteitselement_ecologie_owm eco
          WHERE (eco."DB_ID" = swb_exemption.swce_id)), '|'::text) AS "Kwaliteitselement.Omschrijving",
    array_to_string(ARRAY( SELECT DISTINCT regexp_replace((prio."ChemischeStof_Omschrijving")::text, '\r|\n'::text, ''::text, 'g'::text) AS regexp_replace
           FROM vw_milieudoelstellingen_prioritaire_stof_owm prio
          WHERE (prio."DB_ID" = swb_exemption.swce_id)), '|'::text) AS "PrioritaireStof.Omschrijving",
    hdo_swb.wkrv_id AS versie
   FROM ((swb_exemption
     LEFT JOIN objectives_exemption_type ON ((objectives_exemption_type.obex_id = swb_exemption.obex_id)))
     LEFT JOIN hydro_object hdo_swb ON ((hdo_swb.hdo_id = swb_exemption.swb_id)))
UNION ALL
 SELECT hdo_gwb.inspire_id_local_id AS "Waterlichaam.Identificatie",
    objectives_exemption_type.article_nr AS "Uitzondering.Artikel",
    objectives_exemption_type.name AS "Uitzonderingsgrond",
    NULL::text AS "Artikel4-4.Mechanisme",
    gwb_chemical_exemption.comment AS "Motivatie",
    array_to_string(ARRAY( SELECT DISTINCT regexp_replace((gwk.name)::text, '\r|\n'::text, ''::text, 'g'::text) AS regexp_replace
           FROM vw_milieudoelstellingen_kwaliteitselement_gwl gwk
          WHERE (gwk."DB_ID" = gwb_chemical_exemption.gwce_id)), '|'::text) AS "Kwaliteitselement.Omschrijving",
    NULL::text AS "PrioritaireStof.Omschrijving",
    hdo_gwb.wkrv_id AS versie
   FROM ((gwb_chemical_exemption
     LEFT JOIN objectives_exemption_type ON ((objectives_exemption_type.obex_id = gwb_chemical_exemption.obex_id)))
     LEFT JOIN hydro_object hdo_gwb ON ((hdo_gwb.hdo_id = gwb_chemical_exemption.gwb_id)));


--
-- Name: vw_milieudoelstellingen_art45_tm_art47_owm; Type: VIEW; Schema: public; Owner: -
--

CREATE VIEW vw_milieudoelstellingen_art45_tm_art47_owm AS
 SELECT swb_exemption.swce_id AS "DB_ID",
    hdo_swb.hdo_id AS "Waterlichaam_DB_ID",
    hdo_swb.inspire_id_local_id AS "Waterlichaam_Identificatie",
    objectives_exemption_type.obex_id AS "Motiveringsgrond_DB_ID",
    objectives_exemption_type.name AS "Motiveringsgrond",
    swb_exemption.comment AS "Motivatie"
   FROM ((swb_exemption
     LEFT JOIN objectives_exemption_type ON ((objectives_exemption_type.obex_id = swb_exemption.obex_id)))
     LEFT JOIN hydro_object hdo_swb ON ((hdo_swb.hdo_id = swb_exemption.swb_id)))
  WHERE ((objectives_exemption_type.article_nr)::text <> '4.4'::text);


--
-- Name: vw_milieudoelstellingen_kwaliteitselement_totaal_owm; Type: VIEW; Schema: public; Owner: -
--

CREATE VIEW vw_milieudoelstellingen_kwaliteitselement_totaal_owm AS
 SELECT swb_exemption.swce_id AS "DB_ID",
    hdo_swb.hdo_id AS "Waterlichaam_DB_ID",
    hdo_swb.inspire_id_local_id AS "Waterlichaam_Identificatie",
    objectives_exemption_type.obex_id AS "Motiveringsgrond_DB_ID",
    objectives_exemption_type.name AS "Motiveringsgrond_Omschrijving",
    objectives_exemption_type.article_nr AS "Moviveringsgrond_Artikel",
    swb_exemption.comment AS "Motivering",
    vw_waargenomen_eigenschap."DB_ID" AS "Waargenomen_Eigenschap_DB_ID",
    vw_waargenomen_eigenschap."Tpering_Code",
    vw_waargenomen_eigenschap."Typering_Omschrijving",
    vw_waargenomen_eigenschap."Grootheid_Code",
    vw_waargenomen_eigenschap."Grootheid_Omschrijving",
    vw_waargenomen_eigenschap."ChemischeStof_code",
    vw_waargenomen_eigenschap."ChemischeStof_Omschrijving",
    vw_waargenomen_eigenschap."Hoedanigheid_Code",
    vw_waargenomen_eigenschap."Hoedanigheid_Omschrijving",
    NULL::integer AS "ChemischeStof_DB_ID"
   FROM ((((swb_exemption
     LEFT JOIN objectives_exemption_type ON ((objectives_exemption_type.obex_id = swb_exemption.obex_id)))
     LEFT JOIN swb_ecol_exemp_qe ON ((swb_ecol_exemp_qe.swce_id = swb_exemption.swce_id)))
     LEFT JOIN vw_waargenomen_eigenschap ON ((vw_waargenomen_eigenschap."DB_ID" = swb_ecol_exemp_qe.opt_id)))
     LEFT JOIN hydro_object hdo_swb ON ((hdo_swb.hdo_id = swb_exemption.swb_id)))
UNION ALL
 SELECT swb_exemption.swce_id AS "DB_ID",
    hdo_swb.hdo_id AS "Waterlichaam_DB_ID",
    hdo_swb.inspire_id_local_id AS "Waterlichaam_Identificatie",
    objectives_exemption_type.obex_id AS "Motiveringsgrond_DB_ID",
    objectives_exemption_type.name AS "Motiveringsgrond_Omschrijving",
    objectives_exemption_type.article_nr AS "Moviveringsgrond_Artikel",
    swb_exemption.comment AS "Motivering",
    NULL::integer AS "Waargenomen_Eigenschap_DB_ID",
    NULL::text AS "Tpering_Code",
    NULL::text AS "Typering_Omschrijving",
    'CONCTTE'::text AS "Grootheid_Code",
    '(massa)Concentratie'::text AS "Grootheid_Omschrijving",
    chemische_stof_type.code AS "ChemischeStof_code",
    chemische_stof_type.naam AS "ChemischeStof_Omschrijving",
    'NVT'::text AS "Hoedanigheid_Code",
    'Niet van toepassing'::text AS "Hoedanigheid_Omschrijving",
    chemische_stof_type.chs_id AS "ChemischeStof_DB_ID"
   FROM ((((swb_exemption
     LEFT JOIN objectives_exemption_type ON ((objectives_exemption_type.obex_id = swb_exemption.obex_id)))
     LEFT JOIN swb_chem_exemp_pollutant ON ((swb_chem_exemp_pollutant.swce_id = swb_exemption.swce_id)))
     LEFT JOIN chemische_stof_type ON ((chemische_stof_type.chs_id = swb_chem_exemp_pollutant.chs_id)))
     LEFT JOIN hydro_object hdo_swb ON ((hdo_swb.hdo_id = swb_exemption.swb_id)))
  WHERE (chemische_stof_type.chs_id IS NOT NULL)
  ORDER BY 3, 4, 9, 11, 14;


--
-- Name: vw_monitoring_object_relaties_v15; Type: VIEW; Schema: public; Owner: -
--

CREATE VIEW vw_monitoring_object_relaties_v15 AS
 SELECT hdo_7.inspire_id_namespace_id AS namespace_v7,
    hdo_7.inspire_id_local_id AS identificatie_v7,
    hdo_7.mno_id AS db_id_v7,
        CASE
            WHEN (hdo_7.inspire_id_namespace_id < 10) THEN ((('NL0'::text || (hdo_7.inspire_id_namespace_id)::text) || '_'::text) || (hdo_7.inspire_id_local_id)::text)
            ELSE ((('NL'::text || (hdo_7.inspire_id_namespace_id)::text) || '_'::text) || (hdo_7.inspire_id_local_id)::text)
        END AS mpnident_7,
    hdo_10.inspire_id_namespace_id AS namespace_v10,
    hdo_10.inspire_id_local_id AS identificatie_v10,
    hdo_10.mno_id AS db_id_v10,
        CASE
            WHEN (hdo_10.inspire_id_namespace_id < 10) THEN ((('NL0'::text || (hdo_10.inspire_id_namespace_id)::text) || '_'::text) || (hdo_10.inspire_id_local_id)::text)
            ELSE ((('NL'::text || (hdo_10.inspire_id_namespace_id)::text) || '_'::text) || (hdo_10.inspire_id_local_id)::text)
        END AS mpnident_10,
    hdo_12.inspire_id_namespace_id AS namespace_v12,
    hdo_12.inspire_id_local_id AS identificatie_v12,
    hdo_12.mno_id AS db_id_v12,
        CASE
            WHEN (hdo_12.inspire_id_namespace_id < 10) THEN ((('NL0'::text || (hdo_12.inspire_id_namespace_id)::text) || '_'::text) || (hdo_12.inspire_id_local_id)::text)
            ELSE ((('NL'::text || (hdo_12.inspire_id_namespace_id)::text) || '_'::text) || (hdo_12.inspire_id_local_id)::text)
        END AS mpnident_12,
    hdo_15.inspire_id_namespace_id AS namespace_v15,
    hdo_15.inspire_id_local_id AS identificatie_v15,
    hdo_15.mno_id AS db_id_v15,
        CASE
            WHEN (hdo_15.inspire_id_namespace_id < 10) THEN ((('NL0'::text || (hdo_15.inspire_id_namespace_id)::text) || '_'::text) || (hdo_15.inspire_id_local_id)::text)
            ELSE ((('NL'::text || (hdo_15.inspire_id_namespace_id)::text) || '_'::text) || (hdo_15.inspire_id_local_id)::text)
        END AS mpnident_15
   FROM ((((((monitoring_object hdo_15
     LEFT JOIN related_monitoring_object rho_15 ON ((rho_15.to_mno = hdo_15.mno_id)))
     LEFT JOIN monitoring_object hdo_12 ON (((rho_15.from_mno = hdo_12.mno_id) AND (hdo_12.wkrv_id = 12))))
     LEFT JOIN related_monitoring_object rho_12 ON ((rho_12.to_mno = hdo_12.mno_id)))
     LEFT JOIN monitoring_object hdo_10 ON (((rho_12.from_mno = hdo_10.mno_id) AND (hdo_10.wkrv_id = 10))))
     LEFT JOIN related_monitoring_object rho_10 ON ((rho_10.to_mno = hdo_10.mno_id)))
     LEFT JOIN monitoring_object hdo_7 ON (((rho_10.from_mno = hdo_7.mno_id) AND (hdo_7.wkrv_id = 7))))
  WHERE (hdo_15.wkrv_id = 15)
  ORDER BY hdo_15.inspire_id_namespace_id, hdo_15.inspire_id_local_id;


--
-- Name: vw_oordeel_chemie_owm_g; Type: VIEW; Schema: public; Owner: -
--

CREATE VIEW vw_oordeel_chemie_owm_g AS
 SELECT mvo."Waterlichaam_identificatie",
    mvo."Waterlichaam_Versie",
    mvo.stroomgebieddistrict,
    mvo."Rapportagejaar",
    mvo."Tpering_Code",
    mvo."Grootheid_Code",
    mvo."ChemischeStof_code",
    mvo."Oordeel",
    mvo.geometry_type,
    mrz.geometry,
    mvo."Unique_Key"
   FROM (mv_oordeel_chemie_owm mvo
     JOIN management_regulation_or_restriction_zone mrz ON ((mvo.swb_id = mrz.mrz_id)));


--
-- Name: vw_oordeel_chemie_owm_g_origineel; Type: VIEW; Schema: public; Owner: -
--

CREATE VIEW vw_oordeel_chemie_owm_g_origineel AS
 WITH oordeel AS (
         SELECT DISTINCT ON (sys.sys_id, swcs.opt_id) sys.sys_id,
            sys.swb_id,
            sys.year_of_status,
            swcs.opt_id,
            swcs.swcs_id,
            swcs.css_id,
            hdo_swb.hdo_id,
            hdo_swb.wkrv_id,
            hdo_swb.inspire_id_local_id
           FROM ((sw_chemical_substance_status swcs
             JOIN swb_yearly_status sys ON ((swcs.sys_id = sys.sys_id)))
             JOIN hydro_object hdo_swb ON ((hdo_swb.hdo_id = sys.swb_id)))
          WHERE (swcs.eumg_id = 3)
          ORDER BY sys.sys_id, swcs.opt_id, swcs.wbpm_id DESC
        ), opt AS (
         SELECT observed_property_type.opt_id AS "DB_ID",
            typering_type.code AS "Tpering_Code",
            grootheid_type.code AS "Grootheid_Code",
            chemische_stof_type.code AS "ChemischeStof_code"
           FROM (((observed_property_type
             LEFT JOIN grootheid_type ON ((grootheid_type.grh_id = observed_property_type.quantity_id)))
             LEFT JOIN (chemische_stof_type
             JOIN substance_group_element ON ((chemische_stof_type.chs_id = substance_group_element.chs_id))) ON ((substance_group_element.ssge_id = observed_property_type.substance_group_id)))
             LEFT JOIN typering_type ON ((typering_type.typ_id = observed_property_type.indicator_id)))
        )
 SELECT oordeel.inspire_id_local_id AS "Waterlichaam_identificatie",
    oordeel.wkrv_id AS "Waterlichaam_Versie",
    hdo_rbd.inspire_id_local_id AS stroomgebieddistrict,
    oordeel.year_of_status AS "Rapportagejaar",
    opt."Tpering_Code",
    opt."Grootheid_Code",
    opt."ChemischeStof_code",
    classification_type.description AS "Oordeel",
    geometrytype(mrz.geometry) AS geometry_type,
    mrz.geometry,
    ('CH'::text || oordeel.css_id) AS "Unique_Key"
   FROM ((((((oordeel
     JOIN management_regulation_or_restriction_zone mrz ON ((oordeel.swb_id = mrz.mrz_id)))
     JOIN water_body wb ON ((wb.wbd_id = mrz.mrz_id)))
     JOIN river_basin_disrict rbd ON ((rbd.rbd_id = wb.rbd_id)))
     JOIN hydro_object hdo_rbd ON ((rbd.rbd_id = hdo_rbd.hdo_id)))
     JOIN classification_type ON ((oordeel.swcs_id = classification_type.cls_id)))
     JOIN opt ON ((opt."DB_ID" = oordeel.opt_id)));


--
-- Name: vw_oordeel_chemisch_gwl; Type: VIEW; Schema: public; Owner: -
--

CREATE VIEW vw_oordeel_chemisch_gwl AS
 SELECT gwb_yearly_status.gys_id AS "DB_ID",
    hdo_gwb.hdo_id AS "Waterlichaam_DB_ID",
    hdo_gwb.inspire_id_local_id AS "Waterlichaam_Identificatie",
    gwb_yearly_status.year_of_status AS "Rapportagejaar",
    vw_waargenomen_eigenschap."DB_ID" AS "Waargenomen_Eigenschap_DB_ID",
    vw_waargenomen_eigenschap."Tpering_Code",
    vw_waargenomen_eigenschap."Typering_Omschrijving",
    vw_waargenomen_eigenschap."Grootheid_Code",
    vw_waargenomen_eigenschap."Grootheid_Omschrijving",
    vw_waargenomen_eigenschap."ChemischeStof_code",
    vw_waargenomen_eigenschap."ChemischeStof_Omschrijving",
    vw_waargenomen_eigenschap."Hoedanigheid_Code",
    vw_waargenomen_eigenschap."Hoedanigheid_Omschrijving",
    classification_type.description AS "Oordeel",
    eu_monitoring_goal_type.code AS "Oordeel_Type_Code",
    eu_monitoring_goal_type.description AS "Oordeel_Type_Omschrijving",
    waarde_bepalings_methode_type.code AS "WaardebepalingsMethode_Code",
    waarde_bepalings_methode_type.omschrijving AS "WaardebepalingsMethode_Omschrijving",
    gwb_yearly_status.comment_on_chemical_status AS "Toelichting_ChemischeStatus",
    gwb_yearly_status.comment_on_quantity_status AS "Toelichting_EcologischeStatus",
    gwb_yearly_status.motivation_4no_chemical_status AS "Motivatie_Geen_ChemischeStatus",
    gwb_yearly_status.motivation_4no_quantity_status AS "Motivatie_Geen_EcologischeStatus"
   FROM ((((((gwb_yearly_status
     LEFT JOIN hydro_object hdo_gwb ON ((hdo_gwb.hdo_id = gwb_yearly_status.gwb_id)))
     JOIN gw_chemical_status ON ((gw_chemical_status.gys_id = gwb_yearly_status.gys_id)))
     LEFT JOIN classification_type ON ((gw_chemical_status.clst_id = classification_type.cls_id)))
     LEFT JOIN vw_waargenomen_eigenschap ON ((vw_waargenomen_eigenschap."DB_ID" = gw_chemical_status.opt_id)))
     LEFT JOIN waarde_bepalings_methode_type ON ((waarde_bepalings_methode_type.wbpm_id = gw_chemical_status.wbpm_id)))
     LEFT JOIN eu_monitoring_goal_type ON ((eu_monitoring_goal_type.eumg_id = gw_chemical_status.eumg_id)))
  ORDER BY hdo_gwb.inspire_id_local_id, vw_waargenomen_eigenschap."Tpering_Code", vw_waargenomen_eigenschap."Grootheid_Code", vw_waargenomen_eigenschap."ChemischeStof_code", gwb_yearly_status.year_of_status DESC, eu_monitoring_goal_type.code, waarde_bepalings_methode_type.code;


--
-- Name: vw_oordeel_chemisch_owm; Type: VIEW; Schema: public; Owner: -
--

CREATE VIEW vw_oordeel_chemisch_owm AS
 SELECT swb_yearly_status.sys_id AS "DB_ID",
    hdo_swb.hdo_id AS "Waterlichaam_DB_ID",
    hdo_swb.inspire_id_local_id AS "Waterlichaam_identificatie",
    swb_yearly_status.year_of_status AS "Rapportagejaar",
    vw_waargenomen_eigenschap."DB_ID" AS "Waargenomen_Eigenschap_DB_ID",
    vw_waargenomen_eigenschap."Tpering_Code",
    vw_waargenomen_eigenschap."Typering_Omschrijving",
    vw_waargenomen_eigenschap."Grootheid_Code",
    vw_waargenomen_eigenschap."Grootheid_Omschrijving",
    vw_waargenomen_eigenschap."ChemischeStof_code",
    vw_waargenomen_eigenschap."ChemischeStof_Omschrijving",
    vw_waargenomen_eigenschap."Hoedanigheid_Code",
    vw_waargenomen_eigenschap."Hoedanigheid_Omschrijving",
    classification_type.description AS "Oordeel",
    eu_monitoring_goal_type.code AS "Oordeel_Type_Code",
    eu_monitoring_goal_type.description AS "Oordeel_Type_Omschrijving",
    waarde_bepalings_methode_type.code AS "WaardebepalingsMethode_Code",
    waarde_bepalings_methode_type.omschrijving AS "WaardebepalingsMethode_Omschrijving",
    swb_yearly_status.comment_on_chemical_status AS "Toelichting_ChemischeStatus",
    swb_yearly_status.comment_on_ecological_status AS "Toelichting_EcologischeStatus",
    swb_yearly_status.motivation_4no_chemical_status AS "Motivatie_Geen_ChemischeStatus",
    swb_yearly_status.motivation_4no_ecological_status AS "Motivatie_Geen_EcologischeStatus"
   FROM ((((((swb_yearly_status
     LEFT JOIN hydro_object hdo_swb ON ((hdo_swb.hdo_id = swb_yearly_status.swb_id)))
     JOIN sw_chemical_substance_status ON ((sw_chemical_substance_status.sys_id = swb_yearly_status.sys_id)))
     LEFT JOIN classification_type ON ((sw_chemical_substance_status.swcs_id = classification_type.cls_id)))
     LEFT JOIN vw_waargenomen_eigenschap ON ((vw_waargenomen_eigenschap."DB_ID" = sw_chemical_substance_status.opt_id)))
     LEFT JOIN waarde_bepalings_methode_type ON ((waarde_bepalings_methode_type.wbpm_id = sw_chemical_substance_status.wbpm_id)))
     LEFT JOIN eu_monitoring_goal_type ON ((eu_monitoring_goal_type.eumg_id = sw_chemical_substance_status.eumg_id)))
  ORDER BY hdo_swb.inspire_id_local_id, vw_waargenomen_eigenschap."Tpering_Code", vw_waargenomen_eigenschap."Grootheid_Code", vw_waargenomen_eigenschap."ChemischeStof_code", swb_yearly_status.year_of_status DESC, eu_monitoring_goal_type.code, waarde_bepalings_methode_type.code;


--
-- Name: vw_oordeel_ecologie_owm_g; Type: VIEW; Schema: public; Owner: -
--

CREATE VIEW vw_oordeel_ecologie_owm_g AS
 SELECT mvo."Waterlichaam_identificatie",
    mvo."Waterlichaam_Versie",
    mvo.stroomgebieddistrict,
    mvo."Rapportagejaar",
    mvo."Waargenomen_Eigenschap_DB_ID",
    mvo."Tpering_Code",
    mvo."Grootheid_Code",
    mvo."ChemischeStof_code",
    mvo."Oordeel",
    mvo."Oordeel_Type_ID",
    mvo."WaardebepalingsMethode_ID",
    mvo.geometry_type,
    mrz.geometry,
    mvo."Unique_Key"
   FROM (mv_oordeel_ecologie_owm mvo
     JOIN management_regulation_or_restriction_zone mrz ON ((mvo.swb_id = mrz.mrz_id)));


--
-- Name: vw_oordeel_ecologie_owm_g_origineel; Type: VIEW; Schema: public; Owner: -
--

CREATE VIEW vw_oordeel_ecologie_owm_g_origineel AS
 WITH oordeel AS (
         SELECT DISTINCT ON (sys.sys_id, swes.opt_id) sys.sys_id,
            sys.swb_id,
            sys.year_of_status,
            swes.wbpm_id,
            swes.opt_id,
            swes.eumg_id,
            swes.swes_id,
            swes.ecs_id,
            hdo_swb.hdo_id,
            hdo_swb.wkrv_id,
            hdo_swb.inspire_id_local_id
           FROM ((sw_ecological_status swes
             JOIN swb_yearly_status sys ON ((swes.sys_id = sys.sys_id)))
             JOIN hydro_object hdo_swb ON ((hdo_swb.hdo_id = sys.swb_id)))
          WHERE (swes.eumg_id = 3)
          ORDER BY sys.sys_id, swes.opt_id, swes.wbpm_id DESC
        ), opt AS (
         SELECT observed_property_type.opt_id AS "DB_ID",
            typering_type.code AS "Tpering_Code",
            grootheid_type.code AS "Grootheid_Code",
            chemische_stof_type.code AS "ChemischeStof_code"
           FROM (((observed_property_type
             LEFT JOIN grootheid_type ON ((grootheid_type.grh_id = observed_property_type.quantity_id)))
             LEFT JOIN (chemische_stof_type
             JOIN substance_group_element ON ((chemische_stof_type.chs_id = substance_group_element.chs_id))) ON ((substance_group_element.ssge_id = observed_property_type.substance_group_id)))
             LEFT JOIN typering_type ON ((typering_type.typ_id = observed_property_type.indicator_id)))
        )
 SELECT oordeel.inspire_id_local_id AS "Waterlichaam_identificatie",
    oordeel.wkrv_id AS "Waterlichaam_Versie",
    hdo_rbd.inspire_id_local_id AS stroomgebieddistrict,
    oordeel.year_of_status AS "Rapportagejaar",
    oordeel.opt_id AS "Waargenomen_Eigenschap_DB_ID",
    opt."Tpering_Code",
    opt."Grootheid_Code",
    opt."ChemischeStof_code",
    classification_type.description AS "Oordeel",
    oordeel.eumg_id AS "Oordeel_Type_ID",
    oordeel.wbpm_id AS "WaardebepalingsMethode_ID",
    geometrytype(mrz.geometry) AS geometry_type,
    mrz.geometry,
    ('EC'::text || oordeel.ecs_id) AS "Unique_Key"
   FROM ((((((oordeel
     JOIN management_regulation_or_restriction_zone mrz ON ((oordeel.swb_id = mrz.mrz_id)))
     JOIN water_body wb ON ((wb.wbd_id = oordeel.swb_id)))
     JOIN river_basin_disrict rbd ON ((rbd.rbd_id = wb.rbd_id)))
     JOIN hydro_object hdo_rbd ON ((rbd.rbd_id = hdo_rbd.hdo_id)))
     JOIN classification_type ON ((oordeel.swes_id = classification_type.cls_id)))
     JOIN opt ON ((opt."DB_ID" = oordeel.opt_id)));


--
-- Name: vw_oordeel_ecologisch_owm; Type: VIEW; Schema: public; Owner: -
--

CREATE VIEW vw_oordeel_ecologisch_owm AS
 SELECT swb_yearly_status.sys_id AS "DB_ID",
    hdo_swb.hdo_id AS "Waterlichaam_DB_ID",
    hdo_swb.inspire_id_local_id AS "Waterlichaam_identificatie",
    swb_yearly_status.year_of_status AS "Rapportagejaar",
    vw_waargenomen_eigenschap."DB_ID" AS "Waargenomen_Eigenschap_DB_ID",
    vw_waargenomen_eigenschap."Tpering_Code",
    vw_waargenomen_eigenschap."Typering_Omschrijving",
    vw_waargenomen_eigenschap."Grootheid_Code",
    vw_waargenomen_eigenschap."Grootheid_Omschrijving",
    vw_waargenomen_eigenschap."ChemischeStof_code",
    vw_waargenomen_eigenschap."ChemischeStof_Omschrijving",
    vw_waargenomen_eigenschap."Hoedanigheid_Code",
    vw_waargenomen_eigenschap."Hoedanigheid_Omschrijving",
    classification_type.description AS "Oordeel",
    eu_monitoring_goal_type.code AS "Oordeel_Type_Code",
    eu_monitoring_goal_type.description AS "Oordeel_Type_Omschrijving",
    waarde_bepalings_methode_type.code AS "WaardebepalingsMethode_Code",
    waarde_bepalings_methode_type.omschrijving AS "WaardebepalingsMethode_Omschrijving",
    swb_yearly_status.comment_on_chemical_status AS "Toelichting_ChemischeStatus",
    swb_yearly_status.comment_on_ecological_status AS "Toelichting_EcologischeStatus",
    swb_yearly_status.motivation_4no_chemical_status AS "Motivatie_Geen_ChemischeStatus",
    swb_yearly_status.motivation_4no_ecological_status AS "Motivatie_Geen_EcologischeStatus"
   FROM ((((((swb_yearly_status
     LEFT JOIN hydro_object hdo_swb ON ((hdo_swb.hdo_id = swb_yearly_status.swb_id)))
     JOIN sw_ecological_status ON ((sw_ecological_status.sys_id = swb_yearly_status.sys_id)))
     LEFT JOIN classification_type ON ((sw_ecological_status.swes_id = classification_type.cls_id)))
     LEFT JOIN vw_waargenomen_eigenschap ON ((vw_waargenomen_eigenschap."DB_ID" = sw_ecological_status.opt_id)))
     LEFT JOIN waarde_bepalings_methode_type ON ((waarde_bepalings_methode_type.wbpm_id = sw_ecological_status.wbpm_id)))
     LEFT JOIN eu_monitoring_goal_type ON ((eu_monitoring_goal_type.eumg_id = sw_ecological_status.eumg_id)))
  ORDER BY hdo_swb.inspire_id_local_id, vw_waargenomen_eigenschap."Tpering_Code", vw_waargenomen_eigenschap."Grootheid_Code", vw_waargenomen_eigenschap."ChemischeStof_code", swb_yearly_status.year_of_status DESC, eu_monitoring_goal_type.code, waarde_bepalings_methode_type.code;


--
-- Name: vw_oordeel_kwantiteit_gwl; Type: VIEW; Schema: public; Owner: -
--

CREATE VIEW vw_oordeel_kwantiteit_gwl AS
 SELECT gwb_yearly_status.gys_id AS "DB_ID",
    hdo_gwb.hdo_id AS "Waterlichaam_DB_ID",
    hdo_gwb.inspire_id_local_id AS "Waterlichaam_Identificatie",
    gwb_yearly_status.year_of_status AS "Rapportagejaar",
    vw_waargenomen_eigenschap."DB_ID" AS "Waargenomen_Eigenschap_DB_ID",
    vw_waargenomen_eigenschap."Tpering_Code",
    vw_waargenomen_eigenschap."Typering_Omschrijving",
    vw_waargenomen_eigenschap."Grootheid_Code",
    vw_waargenomen_eigenschap."Grootheid_Omschrijving",
    vw_waargenomen_eigenschap."ChemischeStof_code",
    vw_waargenomen_eigenschap."ChemischeStof_Omschrijving",
    vw_waargenomen_eigenschap."Hoedanigheid_Code",
    vw_waargenomen_eigenschap."Hoedanigheid_Omschrijving",
    classification_type.description AS "Oordeel",
    eu_monitoring_goal_type.code AS "Oordeel_Type_Code",
    eu_monitoring_goal_type.description AS "Oordeel_Type_Omschrijving",
    waarde_bepalings_methode_type.code AS "WaardebepalingsMethode_Code",
    waarde_bepalings_methode_type.omschrijving AS "WaardebepalingsMethode_Omschrijving",
    gwb_yearly_status.comment_on_quantity_status AS "Toelichting_ChemischeStatus",
    gwb_yearly_status.comment_on_quantity_status AS "Toelichting_EcologischeStatus",
    gwb_yearly_status.motivation_4no_quantity_status AS "Motivatie_Geen_ChemischeStatus",
    gwb_yearly_status.motivation_4no_quantity_status AS "Motivatie_Geen_EcologischeStatus"
   FROM ((((((gwb_yearly_status
     LEFT JOIN hydro_object hdo_gwb ON ((hdo_gwb.hdo_id = gwb_yearly_status.gwb_id)))
     JOIN gw_quantity_status ON ((gw_quantity_status.gys_id = gwb_yearly_status.gys_id)))
     LEFT JOIN classification_type ON ((gw_quantity_status.gwst_id = classification_type.cls_id)))
     LEFT JOIN vw_waargenomen_eigenschap ON ((vw_waargenomen_eigenschap."DB_ID" = gw_quantity_status.opt_id)))
     LEFT JOIN waarde_bepalings_methode_type ON ((waarde_bepalings_methode_type.wbpm_id = gw_quantity_status.wbpm_id)))
     LEFT JOIN eu_monitoring_goal_type ON ((eu_monitoring_goal_type.eumg_id = gw_quantity_status.eumg_id)))
  ORDER BY hdo_gwb.inspire_id_local_id, vw_waargenomen_eigenschap."Tpering_Code", vw_waargenomen_eigenschap."Grootheid_Code", vw_waargenomen_eigenschap."ChemischeStof_code", gwb_yearly_status.year_of_status DESC, eu_monitoring_goal_type.code, waarde_bepalings_methode_type.code;


--
-- Name: vw_oordeel_n2000_gwl; Type: VIEW; Schema: public; Owner: -
--

CREATE VIEW vw_oordeel_n2000_gwl AS
 SELECT hdo_gwb.hdo_id AS "Grondwaterlichaam_DB_ID",
    hdo_gwb.inspire_id_local_id AS "Grondwaterlichaam_Identificatie",
    hdon_gwb.name AS "Grondwaterlichaam_Omschrijving",
    hdo_gwb.wkrv_id AS "Grondwaterlichaam_Versie",
    vw_beschermdegebieden."DB_ID" AS "BeschermdGebied_DB_ID",
    vw_beschermdegebieden."Identificatie" AS "BeschermdGebied_Identificatie",
    vw_beschermdegebieden."Omschrijving" AS "BeschermdGebied_Omschrijving",
    vw_beschermdegebieden."Versie_ID" AS "BeschermdGebied_Versie",
    gwb_yearly_status.year_of_status AS "RapportageJaar",
    vw_waargenomen_eigenschap."DB_ID" AS "WaargenomenEigenschap_DB_ID",
    vw_waargenomen_eigenschap."Tpering_Code",
    vw_waargenomen_eigenschap."Typering_Omschrijving",
    classification_type.cls_id AS "Oordeel_DB_ID",
    classification_type.description AS "Oordeel",
    gw_n2000_status.remark
   FROM ((((((gw_n2000_status
     LEFT JOIN gwb_yearly_status ON ((gw_n2000_status.gwsy = gwb_yearly_status.gys_id)))
     LEFT JOIN hydro_object hdo_gwb ON ((hdo_gwb.hdo_id = gwb_yearly_status.gwb_id)))
     LEFT JOIN hdo_names hdon_gwb ON ((hdo_gwb.hdo_id = hdon_gwb.hdo_id)))
     LEFT JOIN vw_beschermdegebieden ON ((vw_beschermdegebieden."DB_ID" = gw_n2000_status.wpa_id)))
     LEFT JOIN classification_type ON ((classification_type.cls_id = gw_n2000_status.cls_id)))
     LEFT JOIN vw_waargenomen_eigenschap ON ((vw_waargenomen_eigenschap."DB_ID" = gw_n2000_status.opt_id)));


--
-- Name: vw_oordeel_n2000_gwl_g; Type: VIEW; Schema: public; Owner: -
--

CREATE VIEW vw_oordeel_n2000_gwl_g AS
 SELECT hdo_gwb.hdo_id AS "Grondwaterlichaam_DB_ID",
    hdo_gwb.inspire_id_local_id AS "Grondwaterlichaam_Identificatie",
    hdon_gwb.name AS "Grondwaterlichaam_Omschrijving",
    hdo_gwb.wkrv_id AS "Grondwaterlichaam_Versie",
    hdo_rbd.inspire_id_local_id AS stroomgebieddistrict,
    hdo_ps.hdo_id AS "BeschermdGebied_DB_ID",
    hdo_ps.inspire_id_local_id AS "BeschermdGebied_Identificatie",
    hdon_ps.name AS "BeschermdGebied_Omschrijving",
    hdo_ps.wkrv_id AS "BeschermdGebied_Versie",
    gwb_yearly_status.year_of_status AS "RapportageJaar",
    gw_n2000_status.opt_id AS "WaargenomenEigenschap_DB_ID",
    classification_type.cls_id AS "Oordeel_DB_ID",
    classification_type.description AS "Oordeel",
    management_regulation_or_restriction_zone.geometry,
    concat(gw_n2000_status.wpa_id, gw_n2000_status.gwsy, gw_n2000_status.opt_id) AS "Unique_Key"
   FROM ((((((((((gw_n2000_status
     JOIN gwb_yearly_status ON ((gw_n2000_status.gwsy = gwb_yearly_status.gys_id)))
     JOIN hydro_object hdo_gwb ON ((hdo_gwb.hdo_id = gwb_yearly_status.gwb_id)))
     JOIN hdo_names hdon_gwb ON ((hdo_gwb.hdo_id = hdon_gwb.hdo_id)))
     JOIN hydro_object hdo_ps ON ((hdo_ps.hdo_id = gw_n2000_status.wpa_id)))
     JOIN hdo_names hdon_ps ON ((hdon_ps.hdo_id = gw_n2000_status.wpa_id)))
     JOIN classification_type ON ((classification_type.cls_id = gw_n2000_status.cls_id)))
     JOIN management_regulation_or_restriction_zone ON ((management_regulation_or_restriction_zone.mrz_id = gw_n2000_status.wpa_id)))
     JOIN water_body ON ((water_body.wbd_id = hdo_gwb.hdo_id)))
     JOIN river_basin_disrict rbd ON ((rbd.rbd_id = water_body.rbd_id)))
     JOIN hydro_object hdo_rbd ON ((rbd.rbd_id = hdo_rbd.hdo_id)));


--
-- Name: vw_oordeel_ontrekking_gwl_g; Type: VIEW; Schema: public; Owner: -
--

CREATE VIEW vw_oordeel_ontrekking_gwl_g AS
 SELECT gw_abstraction_point_status.gwsy_id AS "DB_ID",
    gwb_yearly_status.year_of_status AS "Rapportagejaar",
    hdo_asp.hdo_id AS "Onttrekking_DB_ID",
    hdo_asp.inspire_id_local_id AS "Onttrekking_Identificatie",
    hdon_asp.name AS "Onttrekking_Omschrijving",
    gw_abstraction_point.rewab_code AS "REWAB_Code",
    rewab_type.description AS "REWAB_Type",
    hdo_asp.wkrv_id AS "Onttrekking_Versie",
    hdo_gwb.hdo_id AS "Grondwaterlichaam_DB_ID",
    hdo_gwb.inspire_id_local_id AS "Grondwaterlichaam_Identificatie",
    hdon_gwb.name AS "Grondwaterlichaam_Omschrijving",
    abstraction_point.geometry,
    hdo_rbd.inspire_id_local_id AS "Grondwaterlichaam_Stroomgebieddistrict",
    hdo_gwb.wkrv_id AS "Grondwaterlichaam_Versie",
    classification_type.code AS "Oordeel_Code",
    classification_type.description AS "Oordeel_Omschrijving",
    concat(row_number() OVER (ORDER BY hdo_asp.hdo_id), hdo_gwb.hdo_id, hdo_asp.hdo_id) AS "Unique_Key",
    gw_abstraction_point_status.remarks AS "Opmerkingen"
   FROM ((((((((((((gw_abstraction_point_status
     JOIN abstraction_point ON ((abstraction_point.asp_id = gw_abstraction_point_status.asp_id)))
     JOIN gw_abstraction_point ON ((gw_abstraction_point.gasp_id = gw_abstraction_point_status.asp_id)))
     JOIN hydro_object hdo_asp ON ((hdo_asp.hdo_id = gw_abstraction_point_status.asp_id)))
     JOIN hdo_names hdon_asp ON ((hdon_asp.hdo_id = gw_abstraction_point_status.asp_id)))
     JOIN gwb_yearly_status ON ((gwb_yearly_status.gys_id = gw_abstraction_point_status.gwsy_id)))
     JOIN classification_type ON ((classification_type.cls_id = gw_abstraction_point_status.gwst_id)))
     JOIN hydro_object hdo_gwb ON ((hdo_gwb.hdo_id = gwb_yearly_status.gwb_id)))
     JOIN hdo_names hdon_gwb ON ((hdon_gwb.hdo_id = gwb_yearly_status.gwb_id)))
     JOIN water_body ON ((water_body.wbd_id = hdo_gwb.hdo_id)))
     JOIN river_basin_disrict rbd ON ((rbd.rbd_id = water_body.rbd_id)))
     JOIN hydro_object hdo_rbd ON ((rbd.rbd_id = hdo_rbd.hdo_id)))
     JOIN rewab_type ON ((rewab_type.rwb_id = gw_abstraction_point.rewab_id)));


--
-- Name: vw_oordeel_onttrekking_gwl; Type: VIEW; Schema: public; Owner: -
--

CREATE VIEW vw_oordeel_onttrekking_gwl AS
 SELECT gw_abstraction_point_status.gwsy_id AS "DB_ID",
    gwb_yearly_status.year_of_status AS "Rapportagejaar",
    vw_gw_onttrekking."DB_ID" AS "Onttrekking_DB_ID",
    vw_gw_onttrekking."Identificatie" AS "Onttrekking_Identificatie",
    vw_gw_onttrekking.omschrijving AS "Onttrekking_Omschrijving",
    vw_gw_onttrekking."REWAB_Code" AS "Onttrekking_REWAB_Code",
    vw_gw_onttrekking."REWAB_Type" AS "Onttrekking_REWAB_Type",
    vw_gw_onttrekking.wkr_versie AS "Onttrekking_Versie",
    vw_grondwaterlichamen.db_id AS "Grondwaterlichaam_DB_ID",
    vw_grondwaterlichamen.identificatie AS "Grondwaterlichaam_Identificatie",
    vw_grondwaterlichamen.omschrijving AS "Grondwaterlichaam_Omschrijving",
    vw_grondwaterlichamen.stroomgebieddistrict AS "Grondwaterlichaam_Stroomgebieddistrict",
    vw_grondwaterlichamen.versie AS "Grondwaterlichaam_Versie",
    classification_type.code AS "Oordeel_Code",
    classification_type.description AS "Oordeel_Omschrijving",
    gw_abstraction_point_status.remarks AS "Opmerkingen"
   FROM gw_abstraction_point_status,
    gwb_yearly_status,
    vw_gw_onttrekking,
    classification_type,
    vw_grondwaterlichamen
  WHERE ((gwb_yearly_status.gys_id = gw_abstraction_point_status.gwsy_id) AND (vw_gw_onttrekking."DB_ID" = gw_abstraction_point_status.asp_id) AND (classification_type.cls_id = gw_abstraction_point_status.gwst_id) AND (vw_grondwaterlichamen.db_id = gwb_yearly_status.gwb_id));


--
-- Name: vw_oordeel_owm_tel_stoffen; Type: VIEW; Schema: public; Owner: -
--

CREATE VIEW vw_oordeel_owm_tel_stoffen AS
 WITH oordeel_kwal AS (
         SELECT DISTINCT ON (sys.sys_id, swcs.opt_id) sys.sys_id,
            sys.year_of_status,
            swcs.opt_id,
            swcs.swcs_id,
            sys.swb_id,
            swcs.wbpm_id
           FROM (swb_yearly_status sys
             JOIN sw_chemical_substance_status swcs ON ((swcs.sys_id = sys.sys_id)))
          WHERE ((swcs.opt_id = ANY (ARRAY[4477, 4519, 5893, 5891, 5892])) AND (swcs.eumg_id = 3))
          ORDER BY sys.sys_id, swcs.opt_id, swcs.wbpm_id DESC
        ), oordeel_stof_vn AS (
         SELECT DISTINCT ON (sys.sys_id, swcs.opt_id) sys.sys_id,
            sys.year_of_status,
            swcs.opt_id,
            swcs.swcs_id,
            sge.chs_id
           FROM (((swb_yearly_status sys
             JOIN sw_chemical_substance_status swcs ON ((swcs.sys_id = sys.sys_id)))
             JOIN observed_property_type ON ((observed_property_type.opt_id = swcs.opt_id)))
             JOIN substance_group_element sge ON ((sge.ssge_id = observed_property_type.substance_group_id)))
          WHERE ((sge.chs_id IS NOT NULL) AND (swcs.eumg_id = 3))
          ORDER BY sys.sys_id, swcs.opt_id, swcs.wbpm_id DESC
        ), stofgroep AS (
         SELECT substance_group_element.chs_id,
            substance_group_element.ssge_id,
                CASE substance_group_element.ssge_id
                    WHEN 3155 THEN 4519
                    WHEN 3149 THEN 5892
                    WHEN 3150 THEN 5891
                    WHEN 2907 THEN 4477
                    WHEN 3148 THEN 5893
                    ELSE 0
                END AS categorie
           FROM substance_group_element
          WHERE (substance_group_element.ssge_id = ANY (ARRAY[3155, 3150, 3149, 3148, 2907]))
        ), tel_stof_vn AS (
         SELECT sys.sys_id,
            count(oordeel_stof_vn.swcs_id) AS cnt_oordeel,
            stofgroep.categorie
           FROM ((swb_yearly_status sys
             JOIN oordeel_stof_vn ON ((oordeel_stof_vn.sys_id = sys.sys_id)))
             LEFT JOIN stofgroep ON ((oordeel_stof_vn.chs_id = stofgroep.chs_id)))
          WHERE (oordeel_stof_vn.swcs_id = 2)
          GROUP BY sys.sys_id, stofgroep.categorie
         HAVING (stofgroep.categorie <> 0)
        )
 SELECT (((hdo_swb.inspire_id_local_id)::text || (hdo_swb.wkrv_id)::text) || (oordeel_kwal.year_of_status)::text) AS "Unique_key",
    oordeel_kwal.year_of_status AS "Rapportagejaar",
        CASE
            WHEN (oordeel_kwal.opt_id = 4477) THEN 'CHEMT'::text
            WHEN (oordeel_kwal.opt_id = 4519) THEN 'STOFOV'::text
            WHEN (oordeel_kwal.opt_id = 5893) THEN 'STOFPR_34-45'::text
            WHEN (oordeel_kwal.opt_id = 5891) THEN 'STOFPR_UBQJ'::text
            WHEN (oordeel_kwal.opt_id = 5892) THEN 'STOFPR_UBQN'::text
            ELSE NULL::text
        END AS "STOF_CATEGORIE",
        CASE
            WHEN (tel_stof_vn.cnt_oordeel >= 7) THEN '7+'::text
            WHEN (tel_stof_vn.cnt_oordeel = ANY (ARRAY[(4)::bigint, (5)::bigint, (6)::bigint])) THEN '4-6'::text
            WHEN (tel_stof_vn.cnt_oordeel = ANY (ARRAY[(2)::bigint, (3)::bigint])) THEN '2-3'::text
            WHEN (tel_stof_vn.cnt_oordeel = 1) THEN '1'::text
            WHEN ((oordeel_kwal.swcs_id = 1) AND (tel_stof_vn.cnt_oordeel IS NULL)) THEN '0'::text
            ELSE 'NVT'::text
        END AS classificatie,
    hdo_swb.wkrv_id AS "Waterlichaam_Versie",
    hdo_swb.inspire_id_local_id AS "Waterlichaam_Identificatie",
    hdo_rbd.inspire_id_local_id AS stroomgebieddistrict
   FROM ((((oordeel_kwal
     LEFT JOIN tel_stof_vn ON (((tel_stof_vn.sys_id = oordeel_kwal.sys_id) AND (tel_stof_vn.categorie = oordeel_kwal.opt_id))))
     JOIN hydro_object hdo_swb ON ((hdo_swb.hdo_id = oordeel_kwal.swb_id)))
     JOIN water_body wb ON ((wb.wbd_id = oordeel_kwal.swb_id)))
     JOIN hydro_object hdo_rbd ON ((wb.rbd_id = hdo_rbd.hdo_id)))
  ORDER BY hdo_swb.inspire_id_local_id, oordeel_kwal.year_of_status, hdo_swb.wkrv_id;


--
-- Name: vw_oordeel_owm_tel_stoffen_g; Type: VIEW; Schema: public; Owner: -
--

CREATE VIEW vw_oordeel_owm_tel_stoffen_g AS
 WITH oordeel_kwal AS (
         SELECT DISTINCT ON (sys.sys_id, swcs.opt_id) sys.sys_id,
            sys.year_of_status,
            swcs.opt_id,
            swcs.swcs_id,
            sys.swb_id,
            swcs.wbpm_id
           FROM (swb_yearly_status sys
             JOIN sw_chemical_substance_status swcs ON ((swcs.sys_id = sys.sys_id)))
          WHERE ((swcs.opt_id = ANY (ARRAY[4477, 4519, 5893, 5891, 5892])) AND (swcs.eumg_id = 3))
          ORDER BY sys.sys_id, swcs.opt_id, swcs.wbpm_id DESC
        ), oordeel_stof_vn AS (
         SELECT DISTINCT ON (sys.sys_id, swcs.opt_id) sys.sys_id,
            sys.year_of_status,
            swcs.opt_id,
            swcs.swcs_id,
            sge.chs_id
           FROM (((swb_yearly_status sys
             JOIN sw_chemical_substance_status swcs ON ((swcs.sys_id = sys.sys_id)))
             JOIN observed_property_type ON ((observed_property_type.opt_id = swcs.opt_id)))
             JOIN substance_group_element sge ON ((sge.ssge_id = observed_property_type.substance_group_id)))
          WHERE ((sge.chs_id IS NOT NULL) AND (swcs.eumg_id = 3))
          ORDER BY sys.sys_id, swcs.opt_id, swcs.wbpm_id DESC
        ), stofgroep AS (
         SELECT substance_group_element.chs_id,
            substance_group_element.ssge_id,
                CASE substance_group_element.ssge_id
                    WHEN 3155 THEN 4519
                    WHEN 3149 THEN 5892
                    WHEN 3150 THEN 5891
                    WHEN 2907 THEN 4477
                    WHEN 3148 THEN 5893
                    ELSE 0
                END AS categorie
           FROM substance_group_element
          WHERE (substance_group_element.ssge_id = ANY (ARRAY[3155, 3150, 3149, 3148, 2907]))
        ), tel_stof_vn AS (
         SELECT sys.sys_id,
            count(oordeel_stof_vn.swcs_id) AS cnt_oordeel,
            stofgroep.categorie
           FROM ((swb_yearly_status sys
             JOIN oordeel_stof_vn ON (((oordeel_stof_vn.sys_id = sys.sys_id) AND (oordeel_stof_vn.swcs_id = 2))))
             LEFT JOIN stofgroep ON ((oordeel_stof_vn.chs_id = stofgroep.chs_id)))
          GROUP BY sys.sys_id, stofgroep.categorie
         HAVING (stofgroep.categorie <> 0)
        )
 SELECT (((hdo_swb.inspire_id_local_id)::text || (hdo_swb.wkrv_id)::text) || (oordeel_kwal.year_of_status)::text) AS "Unique_key",
    oordeel_kwal.year_of_status AS "Rapportagejaar",
        CASE
            WHEN (oordeel_kwal.opt_id = 4477) THEN 'CHEMT'::text
            WHEN (oordeel_kwal.opt_id = 4519) THEN 'STOFOV'::text
            WHEN (oordeel_kwal.opt_id = 5893) THEN 'STOFPR_34-45'::text
            WHEN (oordeel_kwal.opt_id = 5891) THEN 'STOFPR_UBQJ'::text
            WHEN (oordeel_kwal.opt_id = 5892) THEN 'STOFPR_UBQN'::text
            ELSE NULL::text
        END AS "STOF_CATEGORIE",
        CASE
            WHEN (tel_stof_vn.cnt_oordeel >= 7) THEN '7+'::text
            WHEN (tel_stof_vn.cnt_oordeel = ANY (ARRAY[(4)::bigint, (5)::bigint, (6)::bigint])) THEN '4-6'::text
            WHEN (tel_stof_vn.cnt_oordeel = ANY (ARRAY[(2)::bigint, (3)::bigint])) THEN '2-3'::text
            WHEN (tel_stof_vn.cnt_oordeel = 1) THEN '1'::text
            WHEN ((oordeel_kwal.swcs_id = 1) AND (tel_stof_vn.cnt_oordeel IS NULL)) THEN '0'::text
            ELSE 'NVT'::text
        END AS classificatie,
    hdo_swb.wkrv_id AS "Waterlichaam_Versie",
    hdo_swb.inspire_id_local_id AS "Waterlichaam_Identificatie",
    geometrytype(mrz.geometry) AS geometry_type,
    mrz.geometry,
    hdo_rbd.inspire_id_local_id AS stroomgebieddistrict
   FROM (((((oordeel_kwal
     LEFT JOIN tel_stof_vn ON (((tel_stof_vn.sys_id = oordeel_kwal.sys_id) AND (tel_stof_vn.categorie = oordeel_kwal.opt_id))))
     JOIN hydro_object hdo_swb ON ((hdo_swb.hdo_id = oordeel_kwal.swb_id)))
     JOIN management_regulation_or_restriction_zone mrz ON ((mrz.mrz_id = oordeel_kwal.swb_id)))
     JOIN water_body wb ON ((wb.wbd_id = oordeel_kwal.swb_id)))
     JOIN hydro_object hdo_rbd ON ((wb.rbd_id = hdo_rbd.hdo_id)))
  ORDER BY hdo_swb.inspire_id_local_id, oordeel_kwal.year_of_status, hdo_swb.wkrv_id;


--
-- Name: vw_oordeel_sbw_gwl; Type: VIEW; Schema: public; Owner: -
--

CREATE VIEW vw_oordeel_sbw_gwl AS
 SELECT hdo_gwb.hdo_id AS "Grondwaterlichaam_DB_ID",
    hdo_gwb.inspire_id_local_id AS "Grondwaterlichaam_Identificatie",
    hdon_gwb.name AS "Grondwaterlichaam_Omschrijving",
    hdo_gwb.wkrv_id AS "Grondwaterlichaam_Versie",
    hdo_swb.hdo_id AS "Oppervlaktewaterlichaam_DB_ID",
    hdo_swb.inspire_id_local_id AS "OppervlakteWaterlichaam_Identificatie",
    hdon_swb.name AS "OppervlakteWaterlichaam_Omschrijving",
    hdo_gwb.wkrv_id AS "OppervlakteWaterlichaam_Versie",
    gwb_yearly_status.year_of_status AS "RapportageJaar",
    vw_waargenomen_eigenschap."DB_ID" AS "WaargenomenEigenschap_DB_ID",
    vw_waargenomen_eigenschap."Tpering_Code",
    vw_waargenomen_eigenschap."Typering_Omschrijving",
    classification_type.cls_id AS "Oordeel_DB_ID",
    classification_type.description AS "Oordeel",
    gw_swb_status.remark
   FROM (((((((gw_swb_status
     LEFT JOIN gwb_yearly_status ON ((gwb_yearly_status.gys_id = gw_swb_status.gwsy)))
     LEFT JOIN hydro_object hdo_swb ON ((hdo_swb.hdo_id = gwb_yearly_status.gwb_id)))
     LEFT JOIN hdo_names hdon_swb ON ((hdo_swb.hdo_id = hdon_swb.hdo_id)))
     LEFT JOIN hydro_object hdo_gwb ON ((hdo_gwb.hdo_id = gw_swb_status.swb_id)))
     LEFT JOIN hdo_names hdon_gwb ON ((hdo_gwb.hdo_id = hdon_gwb.hdo_id)))
     LEFT JOIN vw_waargenomen_eigenschap ON ((vw_waargenomen_eigenschap."DB_ID" = gw_swb_status.opt_id)))
     LEFT JOIN classification_type ON ((gw_swb_status.cls_id = classification_type.cls_id)));


--
-- Name: vw_oordeel_sbw_gwl_g; Type: VIEW; Schema: public; Owner: -
--

CREATE VIEW vw_oordeel_sbw_gwl_g AS
 SELECT hdo_gwb.hdo_id AS "Grondwaterlichaam_DB_ID",
    hdo_gwb.inspire_id_local_id AS "Grondwaterlichaam_Identificatie",
    hdon_gwb.name AS "Grondwaterlichaam_Omschrijving",
    hdo_gwb.wkrv_id AS "Grondwaterlichaam_Versie",
    hdo_swb.hdo_id AS "Oppervlaktewaterlichaam_DB_ID",
    hdo_swb.inspire_id_local_id AS "OppervlakteWaterlichaam_Identificatie",
    hdon_swb.name AS "OppervlakteWaterlichaam_Omschrijving",
    hdo_gwb.wkrv_id AS "OppervlakteWaterlichaam_Versie",
    gwb_yearly_status.year_of_status AS "RapportageJaar",
    gw_swb_status.opt_id AS "WaargenomenEigenschap_DB_ID",
    classification_type.cls_id AS "Oordeel_DB_ID",
    classification_type.description AS "Oordeel",
    hdo_sgb.inspire_id_local_id AS stroomgebieddistrict,
    management_regulation_or_restriction_zone.geometry,
    (((('UK'::text || hdo_gwb.hdo_id) || hdo_swb.hdo_id) || gw_swb_status.opt_id) || gwb_yearly_status.year_of_status) AS "Unique_Key"
   FROM (((((((((gw_swb_status
     JOIN gwb_yearly_status ON ((gwb_yearly_status.gys_id = gw_swb_status.gwsy)))
     JOIN hydro_object hdo_gwb ON ((hdo_gwb.hdo_id = gwb_yearly_status.gwb_id)))
     LEFT JOIN hdo_names hdon_gwb ON ((hdo_gwb.hdo_id = hdon_gwb.hdo_id)))
     JOIN hydro_object hdo_swb ON ((hdo_swb.hdo_id = gw_swb_status.swb_id)))
     JOIN hdo_names hdon_swb ON ((hdo_gwb.hdo_id = hdon_swb.hdo_id)))
     JOIN classification_type ON ((gw_swb_status.cls_id = classification_type.cls_id)))
     JOIN management_regulation_or_restriction_zone ON ((management_regulation_or_restriction_zone.mrz_id = hdo_swb.hdo_id)))
     JOIN water_body wbd ON ((wbd.wbd_id = hdo_gwb.hdo_id)))
     JOIN hydro_object hdo_sgb ON ((hdo_sgb.hdo_id = wbd.rbd_id)));


--
-- Name: vw_oordeel_sbw_gwl_g_type; Type: VIEW; Schema: public; Owner: -
--

CREATE VIEW vw_oordeel_sbw_gwl_g_type AS
 SELECT hdo_gwb.hdo_id AS "Grondwaterlichaam_DB_ID",
    hdo_gwb.inspire_id_local_id AS "Grondwaterlichaam_Identificatie",
    hdon_gwb.name AS "Grondwaterlichaam_Omschrijving",
    hdo_gwb.wkrv_id AS "Grondwaterlichaam_Versie",
    hdo_swb.hdo_id AS "Oppervlaktewaterlichaam_DB_ID",
    hdo_swb.inspire_id_local_id AS "OppervlakteWaterlichaam_Identificatie",
    hdon_swb.name AS "OppervlakteWaterlichaam_Omschrijving",
    hdo_gwb.wkrv_id AS "OppervlakteWaterlichaam_Versie",
    gwb_yearly_status.year_of_status AS "RapportageJaar",
    gw_swb_status.opt_id AS "WaargenomenEigenschap_DB_ID",
    classification_type.cls_id AS "Oordeel_DB_ID",
    classification_type.description AS "Oordeel",
    hdo_sgb.inspire_id_local_id AS stroomgebieddistrict,
    management_regulation_or_restriction_zone.geometry,
    geometrytype(management_regulation_or_restriction_zone.geometry) AS geometry_type,
    (((('UK'::text || hdo_gwb.hdo_id) || hdo_swb.hdo_id) || gw_swb_status.opt_id) || gwb_yearly_status.year_of_status) AS "Unique_Key"
   FROM (((((((((gw_swb_status
     JOIN gwb_yearly_status ON ((gwb_yearly_status.gys_id = gw_swb_status.gwsy)))
     JOIN hydro_object hdo_gwb ON ((hdo_gwb.hdo_id = gwb_yearly_status.gwb_id)))
     LEFT JOIN hdo_names hdon_gwb ON ((hdo_gwb.hdo_id = hdon_gwb.hdo_id)))
     JOIN hydro_object hdo_swb ON ((hdo_swb.hdo_id = gw_swb_status.swb_id)))
     JOIN hdo_names hdon_swb ON ((hdo_gwb.hdo_id = hdon_swb.hdo_id)))
     JOIN classification_type ON ((gw_swb_status.cls_id = classification_type.cls_id)))
     JOIN management_regulation_or_restriction_zone ON ((management_regulation_or_restriction_zone.mrz_id = hdo_swb.hdo_id)))
     JOIN water_body wbd ON ((wbd.wbd_id = hdo_gwb.hdo_id)))
     JOIN hydro_object hdo_sgb ON ((hdo_sgb.hdo_id = wbd.rbd_id)));


--
-- Name: vw_oordeel_totaal_gwl; Type: VIEW; Schema: public; Owner: -
--

CREATE VIEW vw_oordeel_totaal_gwl AS
 SELECT gwb_yearly_status.gys_id AS "DB_ID",
    hdo_gwb.hdo_id AS "Waterlichaam_DB_ID",
    hdo_gwb.inspire_id_local_id AS "Waterlichaam_Identificatie",
    gwb_yearly_status.year_of_status AS "Rapportagejaar",
    vw_waargenomen_eigenschap."DB_ID" AS "Waargenomen_Eigenschap_DB_ID",
    vw_waargenomen_eigenschap."Tpering_Code",
    vw_waargenomen_eigenschap."Typering_Omschrijving",
    vw_waargenomen_eigenschap."Grootheid_Code",
    vw_waargenomen_eigenschap."Grootheid_Omschrijving",
    vw_waargenomen_eigenschap."ChemischeStof_code",
    vw_waargenomen_eigenschap."ChemischeStof_Omschrijving",
    vw_waargenomen_eigenschap."Hoedanigheid_Code",
    vw_waargenomen_eigenschap."Hoedanigheid_Omschrijving",
    classification_type.description AS "Oordeel",
    eu_monitoring_goal_type.code AS "Oordeel_Type_Code",
    eu_monitoring_goal_type.description AS "Oordeel_Type_Omschrijving",
    waarde_bepalings_methode_type.code AS "WaardebepalingsMethode_Code",
    waarde_bepalings_methode_type.omschrijving AS "WaardebepalingsMethode_Omschrijving",
    gwb_yearly_status.comment_on_chemical_status AS "Toelichting_ChemischeStatus",
    gwb_yearly_status.comment_on_quantity_status AS "Toelichting_EcologischeStatus",
    gwb_yearly_status.motivation_4no_chemical_status AS "Motivatie_Geen_ChemischeStatus",
    gwb_yearly_status.motivation_4no_chemical_trends AS "Motivatie_Geen_ChemischeTrend",
    gwb_yearly_status.motivation_4no_quantity_status AS "Motivatie_Geen_EcologischeStatus",
    classification_type.cls_id AS "Oordeel_DB_ID"
   FROM ((((((gwb_yearly_status
     LEFT JOIN hydro_object hdo_gwb ON ((hdo_gwb.hdo_id = gwb_yearly_status.gwb_id)))
     JOIN gw_chemical_status ON ((gw_chemical_status.gys_id = gwb_yearly_status.gys_id)))
     LEFT JOIN classification_type ON ((gw_chemical_status.clst_id = classification_type.cls_id)))
     LEFT JOIN vw_waargenomen_eigenschap ON ((vw_waargenomen_eigenschap."DB_ID" = gw_chemical_status.opt_id)))
     LEFT JOIN waarde_bepalings_methode_type ON ((waarde_bepalings_methode_type.wbpm_id = gw_chemical_status.wbpm_id)))
     LEFT JOIN eu_monitoring_goal_type ON ((eu_monitoring_goal_type.eumg_id = gw_chemical_status.eumg_id)))
UNION ALL
 SELECT gwb_yearly_status.gys_id AS "DB_ID",
    hdo_gwb.hdo_id AS "Waterlichaam_DB_ID",
    hdo_gwb.inspire_id_local_id AS "Waterlichaam_Identificatie",
    gwb_yearly_status.year_of_status AS "Rapportagejaar",
    vw_waargenomen_eigenschap."DB_ID" AS "Waargenomen_Eigenschap_DB_ID",
    vw_waargenomen_eigenschap."Tpering_Code",
    vw_waargenomen_eigenschap."Typering_Omschrijving",
    vw_waargenomen_eigenschap."Grootheid_Code",
    vw_waargenomen_eigenschap."Grootheid_Omschrijving",
    vw_waargenomen_eigenschap."ChemischeStof_code",
    vw_waargenomen_eigenschap."ChemischeStof_Omschrijving",
    vw_waargenomen_eigenschap."Hoedanigheid_Code",
    vw_waargenomen_eigenschap."Hoedanigheid_Omschrijving",
    classification_type.description AS "Oordeel",
    eu_monitoring_goal_type.code AS "Oordeel_Type_Code",
    eu_monitoring_goal_type.description AS "Oordeel_Type_Omschrijving",
    waarde_bepalings_methode_type.code AS "WaardebepalingsMethode_Code",
    waarde_bepalings_methode_type.omschrijving AS "WaardebepalingsMethode_Omschrijving",
    gwb_yearly_status.comment_on_quantity_status AS "Toelichting_ChemischeStatus",
    gwb_yearly_status.comment_on_quantity_status AS "Toelichting_EcologischeStatus",
    gwb_yearly_status.motivation_4no_quantity_status AS "Motivatie_Geen_ChemischeStatus",
    gwb_yearly_status.motivation_4no_chemical_trends AS "Motivatie_Geen_ChemischeTrend",
    gwb_yearly_status.motivation_4no_quantity_status AS "Motivatie_Geen_EcologischeStatus",
    classification_type.cls_id AS "Oordeel_DB_ID"
   FROM ((((((gwb_yearly_status
     LEFT JOIN hydro_object hdo_gwb ON ((hdo_gwb.hdo_id = gwb_yearly_status.gwb_id)))
     JOIN gw_quantity_status ON ((gw_quantity_status.gys_id = gwb_yearly_status.gys_id)))
     LEFT JOIN classification_type ON ((gw_quantity_status.gwst_id = classification_type.cls_id)))
     LEFT JOIN vw_waargenomen_eigenschap ON ((vw_waargenomen_eigenschap."DB_ID" = gw_quantity_status.opt_id)))
     LEFT JOIN waarde_bepalings_methode_type ON ((waarde_bepalings_methode_type.wbpm_id = gw_quantity_status.wbpm_id)))
     LEFT JOIN eu_monitoring_goal_type ON ((eu_monitoring_goal_type.eumg_id = gw_quantity_status.eumg_id)))
  ORDER BY 3, 6, 8, 10, 4 DESC, 15, 17;


--
-- Name: vw_oordeel_totaal_gwl_aquo; Type: VIEW; Schema: public; Owner: -
--

CREATE VIEW vw_oordeel_totaal_gwl_aquo AS
 SELECT hdo_gwb.inspire_id_local_id AS "Waterlichaam.Identificatie",
    gwb_yearly_status.year_of_status AS "Rapportagejaar",
    vw_waargenomen_eigenschap."Tpering_Code" AS "Typering.Code",
    vw_waargenomen_eigenschap."Typering_Omschrijving" AS "Typering.Omschrijving",
    vw_waargenomen_eigenschap."Grootheid_Code" AS "Grootheid.Code",
    vw_waargenomen_eigenschap."Grootheid_Omschrijving" AS "Grootheid.Omschrijving",
    vw_waargenomen_eigenschap."ChemischeStof_code" AS "ChemischeStof.Code",
    vw_waargenomen_eigenschap."ChemischeStof_Omschrijving" AS "ChemischeStof.Omschrijving",
    vw_waargenomen_eigenschap."Hoedanigheid_Code" AS "Hoedanigheid.Code",
    vw_waargenomen_eigenschap."Hoedanigheid_Omschrijving" AS "Hoedanigheid.Omschrijving",
    classification_type.description AS "Oordeel",
    eu_monitoring_goal_type.code AS "Oordeelsoort.Code",
    eu_monitoring_goal_type.description AS "Oordeelsoort.Omschrijving",
    waarde_bepalings_methode_type.code AS "WaardebepalingsMethode.Code",
    waarde_bepalings_methode_type.omschrijving AS "WaardebepalingsMethode.Omschrijving",
    hdo_gwb.wkrv_id AS "Versie"
   FROM ((((((gwb_yearly_status
     LEFT JOIN hydro_object hdo_gwb ON ((hdo_gwb.hdo_id = gwb_yearly_status.gwb_id)))
     JOIN gw_chemical_status ON ((gw_chemical_status.gys_id = gwb_yearly_status.gys_id)))
     LEFT JOIN classification_type ON ((gw_chemical_status.clst_id = classification_type.cls_id)))
     LEFT JOIN vw_waargenomen_eigenschap ON ((vw_waargenomen_eigenschap."DB_ID" = gw_chemical_status.opt_id)))
     LEFT JOIN waarde_bepalings_methode_type ON ((waarde_bepalings_methode_type.wbpm_id = gw_chemical_status.wbpm_id)))
     LEFT JOIN eu_monitoring_goal_type ON ((eu_monitoring_goal_type.eumg_id = gw_chemical_status.eumg_id)))
UNION ALL
 SELECT hdo_gwb.inspire_id_local_id AS "Waterlichaam.Identificatie",
    gwb_yearly_status.year_of_status AS "Rapportagejaar",
    vw_waargenomen_eigenschap."Tpering_Code" AS "Typering.Code",
    vw_waargenomen_eigenschap."Typering_Omschrijving" AS "Typering.Omschrijving",
    vw_waargenomen_eigenschap."Grootheid_Code" AS "Grootheid.Code",
    vw_waargenomen_eigenschap."Grootheid_Omschrijving" AS "Grootheid.Omschrijving",
    vw_waargenomen_eigenschap."ChemischeStof_code" AS "ChemischeStof.Code",
    vw_waargenomen_eigenschap."ChemischeStof_Omschrijving" AS "ChemischeStof.Omschrijving",
    vw_waargenomen_eigenschap."Hoedanigheid_Code" AS "Hoedanigheid.Code",
    vw_waargenomen_eigenschap."Hoedanigheid_Omschrijving" AS "Hoedanigheid.Omschrijving",
    classification_type.description AS "Oordeel",
    eu_monitoring_goal_type.code AS "Oordeelsoort.Code",
    eu_monitoring_goal_type.description AS "Oordeelsoort.Omschrijving",
    waarde_bepalings_methode_type.code AS "WaardebepalingsMethode.Code",
    waarde_bepalings_methode_type.omschrijving AS "WaardebepalingsMethode.Omschrijving",
    hdo_gwb.wkrv_id AS "Versie"
   FROM ((((((gwb_yearly_status
     LEFT JOIN hydro_object hdo_gwb ON ((hdo_gwb.hdo_id = gwb_yearly_status.gwb_id)))
     JOIN gw_quantity_status ON ((gw_quantity_status.gys_id = gwb_yearly_status.gys_id)))
     LEFT JOIN classification_type ON ((gw_quantity_status.gwst_id = classification_type.cls_id)))
     LEFT JOIN vw_waargenomen_eigenschap ON ((vw_waargenomen_eigenschap."DB_ID" = gw_quantity_status.opt_id)))
     LEFT JOIN waarde_bepalings_methode_type ON ((waarde_bepalings_methode_type.wbpm_id = gw_quantity_status.wbpm_id)))
     LEFT JOIN eu_monitoring_goal_type ON ((eu_monitoring_goal_type.eumg_id = gw_quantity_status.eumg_id)))
  ORDER BY 1, 4, 6, 8;


--
-- Name: vw_oordeel_totaal_gwl_g; Type: VIEW; Schema: public; Owner: -
--

CREATE VIEW vw_oordeel_totaal_gwl_g AS
 SELECT gwb_yearly_status.gys_id AS "DB_ID",
    hdo_gwb.hdo_id AS "Waterlichaam_DB_ID",
    hdo_gwb.inspire_id_local_id AS "Waterlichaam_Identificatie",
    gwb.horizon_id AS "Horizont",
    hdo_rbd.inspire_id_local_id AS stroomgebieddistrict,
    hdo_gwb.wkrv_id AS versie,
    gwb_yearly_status.year_of_status AS "Rapportagejaar",
    gw_chemical_status.opt_id AS "Waargenomen_Eigenschap_DB_ID",
    classification_type.description AS "Oordeel",
    eu_monitoring_goal_type.code AS "Oordeel_Type_Code",
    waarde_bepalings_methode_type.code AS "WaardebepalingsMethode_Code",
    classification_type.cls_id AS "Oordeel_DB_ID",
    mrz.geometry,
    concat(row_number() OVER (ORDER BY gw_chemical_status.gwcs_id), '-', gw_chemical_status.gwcs_id) AS "Unique_Key"
   FROM ((((((((((management_regulation_or_restriction_zone mrz
     JOIN gwb_yearly_status ON ((mrz.mrz_id = gwb_yearly_status.gwb_id)))
     JOIN hydro_object hdo_gwb ON ((hdo_gwb.hdo_id = mrz.mrz_id)))
     JOIN gw_chemical_status ON ((gw_chemical_status.gys_id = gwb_yearly_status.gys_id)))
     JOIN classification_type ON ((gw_chemical_status.clst_id = classification_type.cls_id)))
     JOIN waarde_bepalings_methode_type ON ((waarde_bepalings_methode_type.wbpm_id = gw_chemical_status.wbpm_id)))
     JOIN eu_monitoring_goal_type ON ((eu_monitoring_goal_type.eumg_id = gw_chemical_status.eumg_id)))
     JOIN water_body ON ((water_body.wbd_id = hdo_gwb.hdo_id)))
     JOIN river_basin_disrict rbd ON ((rbd.rbd_id = water_body.rbd_id)))
     JOIN hydro_object hdo_rbd ON ((rbd.rbd_id = hdo_rbd.hdo_id)))
     JOIN ground_water_body gwb ON ((gwb.gwb_id = mrz.mrz_id)))
UNION ALL
 SELECT gwb_yearly_status.gys_id AS "DB_ID",
    hdo_gwb.hdo_id AS "Waterlichaam_DB_ID",
    hdo_gwb.inspire_id_local_id AS "Waterlichaam_Identificatie",
    gwb.horizon_id AS "Horizont",
    hdo_rbd.inspire_id_local_id AS stroomgebieddistrict,
    hdo_gwb.wkrv_id AS versie,
    gwb_yearly_status.year_of_status AS "Rapportagejaar",
    gw_quantity_status.opt_id AS "Waargenomen_Eigenschap_DB_ID",
    classification_type.description AS "Oordeel",
    eu_monitoring_goal_type.code AS "Oordeel_Type_Code",
    waarde_bepalings_methode_type.code AS "WaardebepalingsMethode_Code",
    classification_type.cls_id AS "Oordeel_DB_ID",
    mrz.geometry,
    concat(row_number() OVER (ORDER BY gw_quantity_status.gwqs_id), '-', gw_quantity_status.gwqs_id) AS "Unique_Key"
   FROM ((((((((((management_regulation_or_restriction_zone mrz
     JOIN gwb_yearly_status ON ((mrz.mrz_id = gwb_yearly_status.gwb_id)))
     JOIN hydro_object hdo_gwb ON ((hdo_gwb.hdo_id = mrz.mrz_id)))
     JOIN gw_quantity_status ON ((gw_quantity_status.gys_id = gwb_yearly_status.gys_id)))
     JOIN classification_type ON ((gw_quantity_status.gwst_id = classification_type.cls_id)))
     JOIN waarde_bepalings_methode_type ON ((waarde_bepalings_methode_type.wbpm_id = gw_quantity_status.wbpm_id)))
     JOIN eu_monitoring_goal_type ON ((eu_monitoring_goal_type.eumg_id = gw_quantity_status.eumg_id)))
     JOIN water_body ON ((water_body.wbd_id = hdo_gwb.hdo_id)))
     JOIN river_basin_disrict rbd ON ((rbd.rbd_id = water_body.rbd_id)))
     JOIN hydro_object hdo_rbd ON ((rbd.rbd_id = hdo_rbd.hdo_id)))
     JOIN ground_water_body gwb ON ((gwb.gwb_id = mrz.mrz_id)));


--
-- Name: vw_oordeel_totaal_gwl_g_test; Type: VIEW; Schema: public; Owner: -
--

CREATE VIEW vw_oordeel_totaal_gwl_g_test AS
 SELECT gwb_yearly_status.gys_id AS "DB_ID",
    hdo_gwb.hdo_id AS "Waterlichaam_DB_ID",
    hdo_gwb.inspire_id_local_id AS "Waterlichaam_Identificatie",
    gwb.horizon_id AS "Horizont",
    hdo_rbd.inspire_id_local_id AS stroomgebieddistrict,
    hdo_gwb.wkrv_id AS versie,
    gwb_yearly_status.year_of_status AS "Rapportagejaar",
    gw_chemical_status.opt_id AS "Waargenomen_Eigenschap_DB_ID",
    vw_waargenomen_eigenschap."Tpering_Code",
    vw_waargenomen_eigenschap."Grootheid_Code",
    vw_waargenomen_eigenschap."ChemischeStof_code",
    classification_type.description AS "Oordeel",
    eu_monitoring_goal_type.code AS "Oordeel_Type_Code",
    waarde_bepalings_methode_type.code AS "WaardebepalingsMethode_Code",
    classification_type.cls_id AS "Oordeel_DB_ID",
    mrz.geometry,
    concat(row_number() OVER (ORDER BY gw_chemical_status.gwcs_id), '-', gw_chemical_status.gwcs_id) AS "Unique_Key"
   FROM (((((((((((management_regulation_or_restriction_zone mrz
     JOIN gwb_yearly_status ON ((mrz.mrz_id = gwb_yearly_status.gwb_id)))
     JOIN hydro_object hdo_gwb ON ((hdo_gwb.hdo_id = mrz.mrz_id)))
     JOIN gw_chemical_status ON ((gw_chemical_status.gys_id = gwb_yearly_status.gys_id)))
     JOIN classification_type ON ((gw_chemical_status.clst_id = classification_type.cls_id)))
     JOIN waarde_bepalings_methode_type ON ((waarde_bepalings_methode_type.wbpm_id = gw_chemical_status.wbpm_id)))
     JOIN eu_monitoring_goal_type ON ((eu_monitoring_goal_type.eumg_id = gw_chemical_status.eumg_id)))
     JOIN water_body ON ((water_body.wbd_id = hdo_gwb.hdo_id)))
     JOIN river_basin_disrict rbd ON ((rbd.rbd_id = water_body.rbd_id)))
     JOIN hydro_object hdo_rbd ON ((rbd.rbd_id = hdo_rbd.hdo_id)))
     JOIN ground_water_body gwb ON ((gwb.gwb_id = mrz.mrz_id)))
     JOIN vw_waargenomen_eigenschap ON ((vw_waargenomen_eigenschap."DB_ID" = gw_chemical_status.opt_id)))
UNION ALL
 SELECT gwb_yearly_status.gys_id AS "DB_ID",
    hdo_gwb.hdo_id AS "Waterlichaam_DB_ID",
    hdo_gwb.inspire_id_local_id AS "Waterlichaam_Identificatie",
    gwb.horizon_id AS "Horizont",
    hdo_rbd.inspire_id_local_id AS stroomgebieddistrict,
    hdo_gwb.wkrv_id AS versie,
    gwb_yearly_status.year_of_status AS "Rapportagejaar",
    gw_quantity_status.opt_id AS "Waargenomen_Eigenschap_DB_ID",
    vw_waargenomen_eigenschap."Tpering_Code",
    vw_waargenomen_eigenschap."Grootheid_Code",
    vw_waargenomen_eigenschap."ChemischeStof_code",
    classification_type.description AS "Oordeel",
    eu_monitoring_goal_type.code AS "Oordeel_Type_Code",
    waarde_bepalings_methode_type.code AS "WaardebepalingsMethode_Code",
    classification_type.cls_id AS "Oordeel_DB_ID",
    mrz.geometry,
    concat(row_number() OVER (ORDER BY gw_quantity_status.gwqs_id), '-', gw_quantity_status.gwqs_id) AS "Unique_Key"
   FROM (((((((((((management_regulation_or_restriction_zone mrz
     JOIN gwb_yearly_status ON ((mrz.mrz_id = gwb_yearly_status.gwb_id)))
     JOIN hydro_object hdo_gwb ON ((hdo_gwb.hdo_id = mrz.mrz_id)))
     JOIN gw_quantity_status ON ((gw_quantity_status.gys_id = gwb_yearly_status.gys_id)))
     JOIN classification_type ON ((gw_quantity_status.gwst_id = classification_type.cls_id)))
     JOIN waarde_bepalings_methode_type ON ((waarde_bepalings_methode_type.wbpm_id = gw_quantity_status.wbpm_id)))
     JOIN eu_monitoring_goal_type ON ((eu_monitoring_goal_type.eumg_id = gw_quantity_status.eumg_id)))
     JOIN water_body ON ((water_body.wbd_id = hdo_gwb.hdo_id)))
     JOIN river_basin_disrict rbd ON ((rbd.rbd_id = water_body.rbd_id)))
     JOIN hydro_object hdo_rbd ON ((rbd.rbd_id = hdo_rbd.hdo_id)))
     JOIN ground_water_body gwb ON ((gwb.gwb_id = mrz.mrz_id)))
     JOIN vw_waargenomen_eigenschap ON ((vw_waargenomen_eigenschap."DB_ID" = gw_quantity_status.opt_id)));


--
-- Name: vw_oordeel_totaal_owm; Type: VIEW; Schema: public; Owner: -
--

CREATE VIEW vw_oordeel_totaal_owm AS
 SELECT swb_yearly_status.sys_id AS "DB_ID",
    hdo_swb.hdo_id AS "Waterlichaam_DB_ID",
    hdo_swb.inspire_id_local_id AS "Waterlichaam_identificatie",
    hdo_swb.wkrv_id AS "Waterlichaam_Versie",
    swb_yearly_status.year_of_status AS "Rapportagejaar",
    vw_waargenomen_eigenschap."DB_ID" AS "Waargenomen_Eigenschap_DB_ID",
    vw_waargenomen_eigenschap."Tpering_Code",
    vw_waargenomen_eigenschap."Typering_Omschrijving",
    vw_waargenomen_eigenschap."Grootheid_Code",
    vw_waargenomen_eigenschap."Grootheid_Omschrijving",
    vw_waargenomen_eigenschap."ChemischeStof_code",
    vw_waargenomen_eigenschap."ChemischeStof_Omschrijving",
    vw_waargenomen_eigenschap."Hoedanigheid_Code",
    vw_waargenomen_eigenschap."Hoedanigheid_Omschrijving",
    classification_type.cls_id AS "Oordeel_DB_ID",
    classification_type.description AS "Oordeel",
    eu_monitoring_goal_type.eumg_id AS "Oordeel_Type_DB_ID",
    eu_monitoring_goal_type.code AS "Oordeel_Type_Code",
    eu_monitoring_goal_type.description AS "Oordeel_Type_Omschrijving",
    waarde_bepalings_methode_type.code AS "WaardebepalingsMethode_Code",
    waarde_bepalings_methode_type.omschrijving AS "WaardebepalingsMethode_Omschrijving",
    swb_yearly_status.comment_on_chemical_status AS "Toelichting_ChemischeStatus",
    swb_yearly_status.comment_on_ecological_status AS "Toelichting_EcologischeStatus",
    swb_yearly_status.motivation_4no_chemical_status AS "Motivatie_Geen_ChemischeStatus",
    swb_yearly_status.motivation_4no_ecological_status AS "Motivatie_Geen_EcologischeStatus"
   FROM ((((((swb_yearly_status
     LEFT JOIN hydro_object hdo_swb ON ((hdo_swb.hdo_id = swb_yearly_status.swb_id)))
     JOIN sw_chemical_substance_status ON ((sw_chemical_substance_status.sys_id = swb_yearly_status.sys_id)))
     LEFT JOIN classification_type ON ((sw_chemical_substance_status.swcs_id = classification_type.cls_id)))
     LEFT JOIN vw_waargenomen_eigenschap ON ((vw_waargenomen_eigenschap."DB_ID" = sw_chemical_substance_status.opt_id)))
     LEFT JOIN waarde_bepalings_methode_type ON ((waarde_bepalings_methode_type.wbpm_id = sw_chemical_substance_status.wbpm_id)))
     LEFT JOIN eu_monitoring_goal_type ON ((eu_monitoring_goal_type.eumg_id = sw_chemical_substance_status.eumg_id)))
UNION ALL
 SELECT swb_yearly_status.sys_id AS "DB_ID",
    hdo_swb.hdo_id AS "Waterlichaam_DB_ID",
    hdo_swb.inspire_id_local_id AS "Waterlichaam_identificatie",
    hdo_swb.wkrv_id AS "Waterlichaam_Versie",
    swb_yearly_status.year_of_status AS "Rapportagejaar",
    vw_waargenomen_eigenschap."DB_ID" AS "Waargenomen_Eigenschap_DB_ID",
    vw_waargenomen_eigenschap."Tpering_Code",
    vw_waargenomen_eigenschap."Typering_Omschrijving",
    vw_waargenomen_eigenschap."Grootheid_Code",
    vw_waargenomen_eigenschap."Grootheid_Omschrijving",
    vw_waargenomen_eigenschap."ChemischeStof_code",
    vw_waargenomen_eigenschap."ChemischeStof_Omschrijving",
    vw_waargenomen_eigenschap."Hoedanigheid_Code",
    vw_waargenomen_eigenschap."Hoedanigheid_Omschrijving",
    classification_type.cls_id AS "Oordeel_DB_ID",
    classification_type.description AS "Oordeel",
    eu_monitoring_goal_type.eumg_id AS "Oordeel_Type_DB_ID",
    eu_monitoring_goal_type.code AS "Oordeel_Type_Code",
    eu_monitoring_goal_type.description AS "Oordeel_Type_Omschrijving",
    waarde_bepalings_methode_type.code AS "WaardebepalingsMethode_Code",
    waarde_bepalings_methode_type.omschrijving AS "WaardebepalingsMethode_Omschrijving",
    swb_yearly_status.comment_on_chemical_status AS "Toelichting_ChemischeStatus",
    swb_yearly_status.comment_on_ecological_status AS "Toelichting_EcologischeStatus",
    swb_yearly_status.motivation_4no_chemical_status AS "Motivatie_Geen_ChemischeStatus",
    swb_yearly_status.motivation_4no_ecological_status AS "Motivatie_Geen_EcologischeStatus"
   FROM ((((((swb_yearly_status
     LEFT JOIN hydro_object hdo_swb ON ((hdo_swb.hdo_id = swb_yearly_status.swb_id)))
     JOIN sw_ecological_status ON ((sw_ecological_status.sys_id = swb_yearly_status.sys_id)))
     LEFT JOIN classification_type ON ((sw_ecological_status.swes_id = classification_type.cls_id)))
     LEFT JOIN vw_waargenomen_eigenschap ON ((vw_waargenomen_eigenschap."DB_ID" = sw_ecological_status.opt_id)))
     LEFT JOIN waarde_bepalings_methode_type ON ((waarde_bepalings_methode_type.wbpm_id = sw_ecological_status.wbpm_id)))
     LEFT JOIN eu_monitoring_goal_type ON ((eu_monitoring_goal_type.eumg_id = sw_ecological_status.eumg_id)))
  ORDER BY 3, 6, 8, 10, 4 DESC, 15, 17;


--
-- Name: vw_oordeel_totaal_owm_aquo; Type: VIEW; Schema: public; Owner: -
--

CREATE VIEW vw_oordeel_totaal_owm_aquo AS
 SELECT hdo_swb.inspire_id_local_id AS "Waterlichaam.Identificatie",
    hdo_swb.wkrv_id AS "Versie",
    swb_yearly_status.year_of_status AS "Rapportagejaar",
    ('NL'::text || (nt.code)::text) AS "Namespace",
    vw_waargenomen_eigenschap."Tpering_Code" AS "Typering.Code",
    vw_waargenomen_eigenschap."Typering_Omschrijving" AS "Typering.Omschrijving",
    vw_waargenomen_eigenschap."Grootheid_Code" AS "Grootheid.Code",
    vw_waargenomen_eigenschap."Grootheid_Omschrijving" AS "Grootheid.Omschrijving",
    vw_waargenomen_eigenschap."ChemischeStof_code" AS "ChemischeStof.Code",
    vw_waargenomen_eigenschap."ChemischeStof_Omschrijving" AS "ChemischeStof.Omschrijving",
    vw_waargenomen_eigenschap."Hoedanigheid_Code" AS "Hoedanigheid.Code",
    vw_waargenomen_eigenschap."Hoedanigheid_Omschrijving" AS "Hoedanigheid.Omschrijving",
    classification_type.description AS "Oordeel",
    eu_monitoring_goal_type.code AS "Oordeelsoort.Code",
    eu_monitoring_goal_type.description AS "Oordeelsoort.Omschrijving",
    waarde_bepalings_methode_type.code AS "WaardebepalingsMethode.Code",
    waarde_bepalings_methode_type.omschrijving AS "WaardebepalingsMethode.Omschrijving",
    sw_chemical_substance_status.last_change_time
   FROM ((((((((swb_yearly_status
     LEFT JOIN hydro_object hdo_swb ON ((hdo_swb.hdo_id = swb_yearly_status.swb_id)))
     JOIN sw_chemical_substance_status ON ((sw_chemical_substance_status.sys_id = swb_yearly_status.sys_id)))
     LEFT JOIN classification_type ON ((sw_chemical_substance_status.swcs_id = classification_type.cls_id)))
     LEFT JOIN vw_waargenomen_eigenschap ON ((vw_waargenomen_eigenschap."DB_ID" = sw_chemical_substance_status.opt_id)))
     LEFT JOIN waarde_bepalings_methode_type ON ((waarde_bepalings_methode_type.wbpm_id = sw_chemical_substance_status.wbpm_id)))
     LEFT JOIN eu_monitoring_goal_type ON ((eu_monitoring_goal_type.eumg_id = sw_chemical_substance_status.eumg_id)))
     JOIN competentauthority_namespacetype con ON ((con.ns_id = hdo_swb.inspire_id_namespace)))
     JOIN namespace_type nt ON ((nt.ns_id = con.ns_id)))
  WHERE (((vw_waargenomen_eigenschap."Tpering_Code")::text <> 'NUTRIENT'::text) OR (vw_waargenomen_eigenschap."Tpering_Code" IS NULL))
UNION ALL
 SELECT hdo_swb.inspire_id_local_id AS "Waterlichaam.Identificatie",
    hdo_swb.wkrv_id AS "Versie",
    swb_yearly_status.year_of_status AS "Rapportagejaar",
    ('NL'::text || (nt.code)::text) AS "Namespace",
    vw_waargenomen_eigenschap."Tpering_Code" AS "Typering.Code",
    vw_waargenomen_eigenschap."Typering_Omschrijving" AS "Typering.Omschrijving",
    vw_waargenomen_eigenschap."Grootheid_Code" AS "Grootheid.Code",
    vw_waargenomen_eigenschap."Grootheid_Omschrijving" AS "Grootheid.Omschrijving",
    vw_waargenomen_eigenschap."ChemischeStof_code" AS "ChemischeStof.Code",
    vw_waargenomen_eigenschap."ChemischeStof_Omschrijving" AS "ChemischeStof.Omschrijving",
    vw_waargenomen_eigenschap."Hoedanigheid_Code" AS "Hoedanigheid.Code",
    vw_waargenomen_eigenschap."Hoedanigheid_Omschrijving" AS "Hoedanigheid.Omschrijving",
    classification_type.description AS "Oordeel",
    eu_monitoring_goal_type.code AS "Oordeelsoort.Code",
    eu_monitoring_goal_type.description AS "Oordeelsoort.Omschrijving",
    waarde_bepalings_methode_type.code AS "WaardebepalingsMethode.Code",
    waarde_bepalings_methode_type.omschrijving AS "WaardebepalingsMethode.Omschrijving",
    sw_ecological_status.last_change_time
   FROM ((((((((swb_yearly_status
     LEFT JOIN hydro_object hdo_swb ON ((hdo_swb.hdo_id = swb_yearly_status.swb_id)))
     JOIN sw_ecological_status ON ((sw_ecological_status.sys_id = swb_yearly_status.sys_id)))
     LEFT JOIN classification_type ON ((sw_ecological_status.swes_id = classification_type.cls_id)))
     LEFT JOIN vw_waargenomen_eigenschap ON ((vw_waargenomen_eigenschap."DB_ID" = sw_ecological_status.opt_id)))
     LEFT JOIN waarde_bepalings_methode_type ON ((waarde_bepalings_methode_type.wbpm_id = sw_ecological_status.wbpm_id)))
     LEFT JOIN eu_monitoring_goal_type ON ((eu_monitoring_goal_type.eumg_id = sw_ecological_status.eumg_id)))
     JOIN competentauthority_namespacetype con ON ((con.ns_id = hdo_swb.inspire_id_namespace)))
     JOIN namespace_type nt ON ((nt.ns_id = con.ns_id)))
  WHERE (((vw_waargenomen_eigenschap."Tpering_Code")::text <> 'NUTRIENT'::text) OR (vw_waargenomen_eigenschap."Tpering_Code" IS NULL));


--
-- Name: vw_oordeel_totaal_owm_g; Type: VIEW; Schema: public; Owner: -
--

CREATE VIEW vw_oordeel_totaal_owm_g AS
 SELECT swb_yearly_status.sys_id AS "DB_ID",
    hdo_swb.inspire_id_local_id AS "Waterlichaam_identificatie",
    hdo_swb.wkrv_id AS "Waterlichaam_Versie",
    hdo_rbd.inspire_id_local_id AS stroomgebieddistrict,
    swb_yearly_status.year_of_status AS "Rapportagejaar",
    sw_chemical_substance_status.opt_id AS "Waargenomen_Eigenschap_DB_ID",
    vw_waargenomen_eigenschap."Tpering_Code",
    vw_waargenomen_eigenschap."Grootheid_Code",
    vw_waargenomen_eigenschap."ChemischeStof_code",
    classification_type.description AS "Oordeel",
    sw_chemical_substance_status.eumg_id AS "Oordeel_Type_ID",
    sw_chemical_substance_status.wbpm_id AS "WaardebepalingsMethode_ID",
    geometrytype(mrz.geometry) AS geometry_type,
    mrz.geometry,
    ('CH'::text || sw_chemical_substance_status.css_id) AS "Unique_Key"
   FROM ((((((((management_regulation_or_restriction_zone mrz
     JOIN hydro_object hdo_swb ON ((hdo_swb.hdo_id = mrz.mrz_id)))
     JOIN water_body wb ON ((wb.wbd_id = mrz.mrz_id)))
     JOIN river_basin_disrict rbd ON ((rbd.rbd_id = wb.rbd_id)))
     JOIN hydro_object hdo_rbd ON ((rbd.rbd_id = hdo_rbd.hdo_id)))
     JOIN swb_yearly_status ON ((mrz.mrz_id = swb_yearly_status.swb_id)))
     JOIN sw_chemical_substance_status ON ((sw_chemical_substance_status.sys_id = swb_yearly_status.sys_id)))
     JOIN classification_type ON ((sw_chemical_substance_status.swcs_id = classification_type.cls_id)))
     JOIN vw_waargenomen_eigenschap ON ((vw_waargenomen_eigenschap."DB_ID" = sw_chemical_substance_status.opt_id)))
UNION ALL
 SELECT swb_yearly_status.sys_id AS "DB_ID",
    hdo_swb.inspire_id_local_id AS "Waterlichaam_identificatie",
    hdo_swb.wkrv_id AS "Waterlichaam_Versie",
    hdo_rbd.inspire_id_local_id AS stroomgebieddistrict,
    swb_yearly_status.year_of_status AS "Rapportagejaar",
    sw_ecological_status.opt_id AS "Waargenomen_Eigenschap_DB_ID",
    vw_waargenomen_eigenschap."Tpering_Code",
    vw_waargenomen_eigenschap."Grootheid_Code",
    vw_waargenomen_eigenschap."ChemischeStof_code",
    classification_type.description AS "Oordeel",
    sw_ecological_status.eumg_id AS "Oordeel_Type_ID",
    sw_ecological_status.wbpm_id AS "WaardebepalingsMethode_ID",
    geometrytype(mrz.geometry) AS geometry_type,
    mrz.geometry,
    ('EC'::text || sw_ecological_status.ecs_id) AS "Unique_Key"
   FROM ((((((((management_regulation_or_restriction_zone mrz
     JOIN hydro_object hdo_swb ON ((hdo_swb.hdo_id = mrz.mrz_id)))
     JOIN water_body wb ON ((wb.wbd_id = mrz.mrz_id)))
     JOIN river_basin_disrict rbd ON ((rbd.rbd_id = wb.rbd_id)))
     JOIN hydro_object hdo_rbd ON ((rbd.rbd_id = hdo_rbd.hdo_id)))
     JOIN swb_yearly_status ON ((mrz.mrz_id = swb_yearly_status.swb_id)))
     JOIN sw_ecological_status ON ((sw_ecological_status.sys_id = swb_yearly_status.sys_id)))
     JOIN classification_type ON ((sw_ecological_status.swes_id = classification_type.cls_id)))
     JOIN vw_waargenomen_eigenschap ON ((vw_waargenomen_eigenschap."DB_ID" = sw_ecological_status.opt_id)));


--
-- Name: vw_oppervlakte_watertypen; Type: VIEW; Schema: public; Owner: -
--

CREATE VIEW vw_oppervlakte_watertypen AS
 SELECT sw_typology_type.styp_id AS "Watertype_DB_ID",
    sw_typology_type.code AS "Watertype_Code",
    sw_typology_type.description AS "Watertype_Omschrijving",
    sw_category_type.name AS "Watertype_EUCategorie",
    swc1.name AS "Watertype_Werkelijke_Categorie",
    sw_typology_type.is_freshwater AS "ZoetwaterJN",
    eu_intercalibration_type.code AS "IntercalibratieType_Code",
    eu_intercalibration_type.description AS "IntercalibratieType_Omschrijving"
   FROM sw_category_type,
    sw_typology_type,
    sw_category_type swc1,
    eu_intercalibration_type
  WHERE ((sw_category_type.swc_id = sw_typology_type.swc_id) AND (eu_intercalibration_type.icalt = sw_typology_type.icalt_id) AND (swc1.swc_id = sw_typology_type.true_swc_id))
  ORDER BY sw_typology_type.code;


--
-- Name: vw_oppervlaktewaterlichaam_kaart_bb; Type: VIEW; Schema: public; Owner: -
--

CREATE VIEW vw_oppervlaktewaterlichaam_kaart_bb AS
 SELECT swb.swb_id AS db_id,
    hydro_object.inspire_id_local_id AS owmident,
    st_extent(mrz.geometry) AS extent,
    hydro_object.wkrv_id AS versie
   FROM ((surface_water_body swb
     LEFT JOIN hydro_object ON ((swb.swb_id = hydro_object.hdo_id)))
     LEFT JOIN management_regulation_or_restriction_zone mrz ON ((swb.swb_id = mrz.mrz_id)))
  GROUP BY swb.swb_id, hydro_object.inspire_id_local_id, hydro_object.wkrv_id
  ORDER BY hydro_object.inspire_id_local_id, hydro_object.wkrv_id;


--
-- Name: watercourse; Type: TABLE; Schema: public; Owner: -
--

CREATE TABLE watercourse (
    wtc_id integer NOT NULL,
    neighbour_id integer,
    length double precision,
    width_lower double precision,
    width_upper double precision,
    "geometryLine" geometry(MultiLineString,28992),
    last_change_time timestamp without time zone NOT NULL,
    "geometrySurface" geometry(MultiPolygon,28992)
);


--
-- Name: vw_oppervlaktewaterlichaam_upload_shape_l; Type: VIEW; Schema: public; Owner: -
--

CREATE VIEW vw_oppervlaktewaterlichaam_upload_shape_l AS
 SELECT hydro_object.hdo_id AS owa_db_id,
    hydro_object.inspire_id_local_id AS owaident,
    hdo_names.name AS owanaam,
    watercourse."geometryLine" AS geometryline,
    hydro_object.wkrv_id AS owa_versie,
    hydro_object2.hdo_id AS owm_db_id,
    hydro_object2.inspire_id_local_id AS owmident,
    hydro_object2.inspire_id_namespace AS namespac,
    vw_competent_authority."Identificatie" AS wbhcode,
    vw_competent_authority."Omschrijving" AS wbhnaam,
    water_body.is_article_7 AS owmcons,
    hdo_names2.name AS owmnaam,
    hdo2.inspire_id_local_id AS sgbident,
        CASE
            WHEN (surface_water_body.is_artificial = true) THEN 'Kunstmatig'::text
            WHEN (surface_water_body.is_heaviliy_modified = true) THEN 'Sterk veranderd'::text
            ELSE 'Natuurlijk'::text
        END AS owmstat,
    surface_water_body.area_value AS owmoppvl,
    surface_water_body.length_value AS owmlengt,
    type.code AS owmtype,
    typer.code AS owmtyped,
    water_body.level_of_detail AS schaal,
    management_regulation_or_restriction_zone.begin_designation AS geldig_b,
    management_regulation_or_restriction_zone.end_designation AS geldig_e
   FROM (((((((((((((watercourse
     LEFT JOIN hydro_object ON ((hydro_object.hdo_id = watercourse.wtc_id)))
     LEFT JOIN hdo_names ON ((hdo_names.hdo_id = hydro_object.hdo_id)))
     LEFT JOIN hydro_object hydro_object2 ON ((hydro_object2.hdo_id = hydro_object.related_hdo_id)))
     LEFT JOIN hdo_names hdo_names2 ON ((hdo_names2.hdo_id = hydro_object2.hdo_id)))
     LEFT JOIN wkr_version ON ((wkr_version.wkrv_id = hydro_object.wkrv_id)))
     LEFT JOIN management_regulation_or_restriction_zone ON ((management_regulation_or_restriction_zone.mrz_id = hydro_object2.hdo_id)))
     LEFT JOIN water_body ON ((water_body.wbd_id = hydro_object2.hdo_id)))
     LEFT JOIN hydro_object hdo2 ON ((hdo2.hdo_id = water_body.rbd_id)))
     LEFT JOIN surface_water_body ON ((surface_water_body.swb_id = hydro_object2.hdo_id)))
     LEFT JOIN sw_typology_type type ON ((type.styp_id = surface_water_body.sw_typology_id)))
     LEFT JOIN sw_typology_type typer ON ((typer.styp_id = surface_water_body.sw_target_typology_id)))
     LEFT JOIN competentauthority_namespacetype ON ((competentauthority_namespacetype.ns_id = hydro_object2.inspire_id_namespace)))
     LEFT JOIN vw_competent_authority ON ((vw_competent_authority."DB_ID" = competentauthority_namespacetype.ore_id)))
  ORDER BY hydro_object.inspire_id_local_id, wkr_version.wkrv_id DESC;


--
-- Name: vw_oppervlaktewaterlichaam_upload_shape_v; Type: VIEW; Schema: public; Owner: -
--

CREATE VIEW vw_oppervlaktewaterlichaam_upload_shape_v AS
 SELECT hydro_object.hdo_id AS owa_db_id,
    hydro_object.inspire_id_local_id AS owaident,
    hdo_names.name AS owanaam,
    watercourse."geometrySurface" AS geometrysurface,
    hydro_object.wkrv_id AS owa_versie,
    hydro_object2.hdo_id AS owm_db_id,
    hydro_object2.inspire_id_local_id AS owmident,
    hydro_object2.inspire_id_namespace AS namespac,
    vw_competent_authority."Identificatie" AS wbhcode,
    vw_competent_authority."Omschrijving" AS wbhnaam,
    water_body.is_article_7 AS owmcons,
    hdo_names2.name AS owmnaam,
    hdo2.inspire_id_local_id AS sgbident,
        CASE
            WHEN (surface_water_body.is_artificial = true) THEN 'Kunstmatig'::text
            WHEN (surface_water_body.is_heaviliy_modified = true) THEN 'Sterk veranderd'::text
            ELSE 'Natuurlijk'::text
        END AS owmstat,
    surface_water_body.area_value AS owmoppvl,
    surface_water_body.length_value AS owmlengt,
    type.code AS owmtype,
    typer.code AS owmtyped,
    water_body.level_of_detail AS schaal,
    management_regulation_or_restriction_zone.begin_designation AS geldig_b,
    management_regulation_or_restriction_zone.end_designation AS geldig_e
   FROM (((((((((((((watercourse
     LEFT JOIN hydro_object ON ((hydro_object.hdo_id = watercourse.wtc_id)))
     LEFT JOIN hdo_names ON ((hdo_names.hdo_id = hydro_object.hdo_id)))
     LEFT JOIN hydro_object hydro_object2 ON ((hydro_object2.hdo_id = hydro_object.related_hdo_id)))
     LEFT JOIN hdo_names hdo_names2 ON ((hdo_names2.hdo_id = hydro_object2.hdo_id)))
     LEFT JOIN wkr_version ON ((wkr_version.wkrv_id = hydro_object.wkrv_id)))
     LEFT JOIN management_regulation_or_restriction_zone ON ((management_regulation_or_restriction_zone.mrz_id = hydro_object2.hdo_id)))
     LEFT JOIN water_body ON ((water_body.wbd_id = hydro_object2.hdo_id)))
     LEFT JOIN hydro_object hdo2 ON ((hdo2.hdo_id = water_body.rbd_id)))
     LEFT JOIN surface_water_body ON ((surface_water_body.swb_id = hydro_object2.hdo_id)))
     LEFT JOIN sw_typology_type type ON ((type.styp_id = surface_water_body.sw_typology_id)))
     LEFT JOIN sw_typology_type typer ON ((typer.styp_id = surface_water_body.sw_target_typology_id)))
     LEFT JOIN competentauthority_namespacetype ON ((competentauthority_namespacetype.ns_id = hydro_object2.inspire_id_namespace)))
     LEFT JOIN vw_competent_authority ON ((vw_competent_authority."DB_ID" = competentauthority_namespacetype.ore_id)))
  ORDER BY hydro_object.inspire_id_local_id, wkr_version.wkrv_id DESC;


--
-- Name: vw_oppervlaktewaterlichamen_aquo; Type: VIEW; Schema: public; Owner: -
--

CREATE VIEW vw_oppervlaktewaterlichamen_aquo AS
 SELECT owa.identificatie AS "Waterlichaam.Identificatie",
    owa.omschrijving AS "Waterlichaam.Omschrijving",
    owa.waterbeheerder_code AS "Waterbeheerder.Code",
    wl.waterbeheerder_naam AS "Waterbeheerder.Omschrijving",
        CASE owa.stroomgebieddistrict
            WHEN 'NLRNNO'::text THEN 'NLRN'::text
            WHEN 'NLRNOO'::text THEN 'NLRN'::text
            WHEN 'NLRNWE'::text THEN 'NLRN'::text
            WHEN 'NLRNMI'::text THEN 'NLRN'::text
            WHEN 'NLSC'::text THEN 'NLSC'::text
            WHEN 'NLMS'::text THEN 'NLMS'::text
            WHEN 'NLEM'::text THEN 'NLEM'::text
            WHEN 'NLRN'::text THEN 'NLRN'::text
            ELSE NULL::text
        END AS "Stroomgebieddistrict.Code",
    owa.stroomgebieddistrict AS "Deelstroomgebieddistrict.Code",
        CASE
            WHEN (owa.is_kunstmatig = true) THEN 'Kunstmatig'::text
            WHEN (owa.is_sterk_veranderd = true) THEN 'Sterk veranderd'::text
            ELSE 'Natuurlijk'::text
        END AS status,
    owa.type AS "Waterlichaam.type",
    owa.referentietype AS "Waterlichaam.doeltype",
        CASE owa.drinkwateronttrekking_jn
            WHEN true THEN 'Drinkwateronttrekking'::text
            WHEN false THEN ''::text
            ELSE NULL::text
        END AS "Drinkwateronttrekking",
    owa.versie
   FROM (vw_oppervlaktewaterlichamen owa
     JOIN vw_waterlichamen wl ON ((wl.db_id = owa.db_id)))
  ORDER BY owa.waterbeheerder_code;


--
-- Name: vw_oppervlaktewaterlichamen_g; Type: VIEW; Schema: public; Owner: -
--

CREATE VIEW vw_oppervlaktewaterlichamen_g AS
 SELECT hydro_object.hdo_id AS db_id,
    hydro_object.inspire_id_local_id AS identificatie,
    hydro_object.inspire_id_namespace AS waterbeheerder_code,
    water_body.is_article_7 AS drinkwateronttrekking_jn,
    hdo_names.name AS omschrijving,
    management_regulation_or_restriction_zone.geometry,
    hdo2.inspire_id_local_id AS stroomgebieddistrict,
    hydro_object.wkrv_id AS versie,
    surface_water_body.is_artificial AS is_kunstmatig,
    surface_water_body.is_heaviliy_modified AS is_sterk_veranderd,
    type.code AS type,
    typer.code AS referentietype
   FROM (((((((management_regulation_or_restriction_zone
     JOIN hydro_object ON ((management_regulation_or_restriction_zone.mrz_id = hydro_object.hdo_id)))
     LEFT JOIN hdo_names ON ((hdo_names.hdo_id = hydro_object.hdo_id)))
     JOIN water_body ON ((water_body.wbd_id = hydro_object.hdo_id)))
     JOIN hydro_object hdo2 ON ((hdo2.hdo_id = water_body.rbd_id)))
     JOIN surface_water_body ON ((surface_water_body.swb_id = hydro_object.hdo_id)))
     JOIN sw_typology_type type ON ((type.styp_id = surface_water_body.sw_typology_id)))
     JOIN sw_typology_type typer ON ((typer.styp_id = surface_water_body.sw_target_typology_id)));


--
-- Name: vw_oppervlaktewaterlichamen_g_type; Type: VIEW; Schema: public; Owner: -
--

CREATE VIEW vw_oppervlaktewaterlichamen_g_type AS
 SELECT hydro_object.hdo_id AS db_id,
    hydro_object.inspire_id_local_id AS identificatie,
    hydro_object.inspire_id_namespace AS waterbeheerder_code,
    water_body.is_article_7 AS drinkwateronttrekking_jn,
    hdo_names.name AS omschrijving,
    management_regulation_or_restriction_zone.geometry,
    geometrytype(management_regulation_or_restriction_zone.geometry) AS geometry_type,
    hdo2.inspire_id_local_id AS stroomgebieddistrict,
    hydro_object.wkrv_id AS versie,
    surface_water_body.is_artificial AS is_kunstmatig,
    surface_water_body.is_heaviliy_modified AS is_sterk_veranderd,
    type.code AS type,
    typer.code AS referentietype
   FROM (((((((management_regulation_or_restriction_zone
     JOIN hydro_object ON ((management_regulation_or_restriction_zone.mrz_id = hydro_object.hdo_id)))
     JOIN water_body ON ((water_body.wbd_id = hydro_object.hdo_id)))
     LEFT JOIN hdo_names ON ((hdo_names.hdo_id = hydro_object.hdo_id)))
     JOIN hydro_object hdo2 ON ((hdo2.hdo_id = water_body.rbd_id)))
     JOIN surface_water_body ON ((surface_water_body.swb_id = hydro_object.hdo_id)))
     JOIN sw_typology_type type ON ((type.styp_id = surface_water_body.sw_typology_id)))
     JOIN sw_typology_type typer ON ((typer.styp_id = surface_water_body.sw_target_typology_id)));


--
-- Name: vw_oppervlaktewaterlichamen_g_type_simple; Type: VIEW; Schema: public; Owner: -
--

CREATE VIEW vw_oppervlaktewaterlichamen_g_type_simple AS
 SELECT hydro_object.hdo_id AS db_id,
    hydro_object.inspire_id_local_id AS identificatie,
    hydro_object.inspire_id_namespace AS waterbeheerder_code,
    water_body.is_article_7 AS drinkwateronttrekking_jn,
    hdo_names.name AS omschrijving,
    st_simplify(management_regulation_or_restriction_zone.geometry, (100)::double precision) AS geometry,
    geometrytype(management_regulation_or_restriction_zone.geometry) AS geometry_type,
    hdo2.inspire_id_local_id AS stroomgebieddistrict,
    hydro_object.wkrv_id AS versie,
    surface_water_body.is_artificial AS is_kunstmatig,
    surface_water_body.is_heaviliy_modified AS is_sterk_veranderd,
    type.code AS type,
    typer.code AS referentietype
   FROM (((((((management_regulation_or_restriction_zone
     JOIN hydro_object ON ((management_regulation_or_restriction_zone.mrz_id = hydro_object.hdo_id)))
     JOIN water_body ON ((water_body.wbd_id = hydro_object.hdo_id)))
     LEFT JOIN hdo_names ON ((hdo_names.hdo_id = hydro_object.hdo_id)))
     JOIN hydro_object hdo2 ON ((hdo2.hdo_id = water_body.rbd_id)))
     JOIN surface_water_body ON ((surface_water_body.swb_id = hydro_object.hdo_id)))
     JOIN sw_typology_type type ON ((type.styp_id = surface_water_body.sw_typology_id)))
     JOIN sw_typology_type typer ON ((typer.styp_id = surface_water_body.sw_target_typology_id)));


--
-- Name: vw_oppervlaktewaterlichamen_shape; Type: VIEW; Schema: public; Owner: -
--

CREATE VIEW vw_oppervlaktewaterlichamen_shape AS
 SELECT hydro_object.hdo_id AS db_id,
    hydro_object.inspire_id_local_id AS owmident,
    hydro_object.inspire_id_namespace AS namespac,
    vw_competent_authority."Omschrijving" AS wbhcode,
    water_body.is_article_7 AS owmcons,
    hdo_names.name AS owmnaam,
    management_regulation_or_restriction_zone.geometry,
    hdo2.inspire_id_local_id AS sgbident,
        CASE
            WHEN (surface_water_body.is_artificial = true) THEN 'Kunstmatig'::text
            WHEN (surface_water_body.is_heaviliy_modified = true) THEN 'Sterk veranderd'::text
            ELSE 'Natuurlijk'::text
        END AS owmstat,
    surface_water_body.area_value AS oppvte,
    surface_water_body.length_value AS lengte,
    type.code AS owmtype,
    typer.code AS owmtyped,
    water_body.level_of_detail AS schaal,
    management_regulation_or_restriction_zone.begin_designation AS geldig_b,
    management_regulation_or_restriction_zone.end_designation AS geldig_e
   FROM ((((((((((hydro_object
     LEFT JOIN hdo_names ON ((hdo_names.hdo_id = hydro_object.hdo_id)))
     JOIN wkr_version ON ((wkr_version.wkrv_id = hydro_object.wkrv_id)))
     JOIN management_regulation_or_restriction_zone ON ((management_regulation_or_restriction_zone.mrz_id = hydro_object.hdo_id)))
     JOIN water_body ON ((water_body.wbd_id = hydro_object.hdo_id)))
     JOIN hydro_object hdo2 ON ((hdo2.hdo_id = water_body.rbd_id)))
     JOIN surface_water_body ON ((surface_water_body.swb_id = hydro_object.hdo_id)))
     JOIN sw_typology_type type ON ((type.styp_id = surface_water_body.sw_typology_id)))
     JOIN sw_typology_type typer ON ((typer.styp_id = surface_water_body.sw_target_typology_id)))
     LEFT JOIN competentauthority_namespacetype ON ((competentauthority_namespacetype.ns_id = hydro_object.inspire_id_namespace)))
     LEFT JOIN vw_competent_authority ON ((vw_competent_authority."DB_ID" = competentauthority_namespacetype.ore_id)))
  ORDER BY hydro_object.inspire_id_local_id, wkr_version.wkrv_id DESC;


--
-- Name: vw_ow_onttrekking; Type: VIEW; Schema: public; Owner: -
--

CREATE VIEW vw_ow_onttrekking AS
 SELECT hydro_object.hdo_id AS "DB_ID",
    hydro_object.inspire_id_local_id AS "Identificatie",
    hdo_names.name AS omschrijving,
    sw_abstraction_point.waterabstraction_from AS "OntrekkingsPunt",
    sw_abstraction_point.swat_id AS "REWAB_Code",
    sw_abstraction_type.description AS "Onttrekking_Type",
    wkr_version.wkrv_id AS wkr_versie,
    wkr_version.begin_lifespan_version AS wkr_beginversie,
    wkr_version.end_lifespan_version AS wkr_eindversie
   FROM ((((((hydro_object
     LEFT JOIN hdo_names ON ((hdo_names.hdo_id = hydro_object.hdo_id)))
     JOIN abstraction_point ON ((hydro_object.hdo_id = abstraction_point.asp_id)))
     JOIN sw_abstraction_point ON ((hydro_object.hdo_id = sw_abstraction_point.sasp_id)))
     JOIN rewab_type ON ((rewab_type.rwb_id = sw_abstraction_point.rewab_id)))
     JOIN sw_abstraction_type ON ((sw_abstraction_type.swat_id = sw_abstraction_point.swat_id)))
     JOIN wkr_version ON ((wkr_version.wkrv_id = hydro_object.wkrv_id)))
  ORDER BY hydro_object.inspire_id_local_id, wkr_version.wkrv_id DESC;


--
-- Name: vw_ow_onttrekking_g; Type: VIEW; Schema: public; Owner: -
--

CREATE VIEW vw_ow_onttrekking_g AS
 SELECT hydro_object.hdo_id AS "DB_ID",
    hydro_object.inspire_id_local_id AS "Identificatie",
    hdo_names.name AS omschrijving,
    abstraction_point.geometry,
    sw_abstraction_point.waterabstraction_from AS "OntrekkingsPunt",
    sw_abstraction_point.swat_id AS "REWAB_Code",
    sw_abstraction_type.description AS "Onttrekking_Type",
    hydro_object.wkrv_id AS wkr_versie,
    (hdo2.stroomgebieddistrict)::text AS "Stroomgebieddistrict"
   FROM ((((((hydro_object
     LEFT JOIN hdo_names ON ((hdo_names.hdo_id = hydro_object.hdo_id)))
     JOIN abstraction_point ON ((hydro_object.hdo_id = abstraction_point.asp_id)))
     JOIN sw_abstraction_point ON ((hydro_object.hdo_id = sw_abstraction_point.sasp_id)))
     JOIN rewab_type ON ((rewab_type.rwb_id = sw_abstraction_point.rewab_id)))
     JOIN sw_abstraction_type ON ((sw_abstraction_type.swat_id = sw_abstraction_point.swat_id)))
     LEFT JOIN vw_oppervlaktewaterlichamen hdo2 ON ((hdo2.db_id = abstraction_point.wbd_id)));


--
