-- Name: vw_groundwaterbody_gwchemicalreasonsforfailure; Type: VIEW; Schema: wfd_reporting; Owner: -
--

CREATE VIEW vw_groundwaterbody_gwchemicalreasonsforfailure AS
 WITH gwb_oordeel AS (
         SELECT hdo_gwb.hdo_id AS gwb_id,
            gwb_yearly_status.year_of_status AS jaar,
            gw_chemical_status.opt_id,
            classification_type.description AS oordeel,
            waarde_bepalings_methode_type.code AS wbpm
           FROM ((((public.gwb_yearly_status
             LEFT JOIN public.hydro_object hdo_gwb ON ((hdo_gwb.hdo_id = gwb_yearly_status.gwb_id)))
             JOIN public.gw_chemical_status ON ((gw_chemical_status.gys_id = gwb_yearly_status.gys_id)))
             LEFT JOIN public.classification_type ON ((gw_chemical_status.clst_id = classification_type.cls_id)))
             LEFT JOIN public.waarde_bepalings_methode_type ON ((waarde_bepalings_methode_type.wbpm_id = gw_chemical_status.wbpm_id)))
          WHERE ((hdo_gwb.wkrv_id = 13) AND (gwb_yearly_status.year_of_status = ANY (ARRAY[2014, 2015])) AND ((waarde_bepalings_methode_type.code)::text = 'GWPROTNL'::text) AND (gw_chemical_status.opt_id = ANY (ARRAY[4495, 4494])))
        UNION ALL
         SELECT hdo_gwb.hdo_id AS gwb_id,
            gwb_yearly_status.year_of_status AS jaar,
            gw_quantity_status.opt_id,
            classification_type.description AS oordeel,
            waarde_bepalings_methode_type.code AS wbpm
           FROM ((((public.gwb_yearly_status
             LEFT JOIN public.hydro_object hdo_gwb ON ((hdo_gwb.hdo_id = gwb_yearly_status.gwb_id)))
             JOIN public.gw_quantity_status ON ((gw_quantity_status.gys_id = gwb_yearly_status.gys_id)))
             LEFT JOIN public.classification_type ON ((gw_quantity_status.gwst_id = classification_type.cls_id)))
             LEFT JOIN public.waarde_bepalings_methode_type ON ((waarde_bepalings_methode_type.wbpm_id = gw_quantity_status.wbpm_id)))
          WHERE ((hdo_gwb.wkrv_id = 13) AND (gwb_yearly_status.year_of_status = ANY (ARRAY[2014, 2015])) AND ((waarde_bepalings_methode_type.code)::text = 'GWPROTNL'::text) AND (gw_quantity_status.opt_id = ANY (ARRAY[4495, 4494])))
        ), gwb_oordeel_sub AS (
         SELECT hdo_gwb.hdo_id AS gwb_id,
            gwb_yearly_status.year_of_status AS jaar,
            gw_chemical_status.opt_id,
            classification_type.description AS oordeel,
            waarde_bepalings_methode_type.code AS wbpm
           FROM ((((public.gwb_yearly_status
             LEFT JOIN public.hydro_object hdo_gwb ON ((hdo_gwb.hdo_id = gwb_yearly_status.gwb_id)))
             JOIN public.gw_chemical_status ON ((gw_chemical_status.gys_id = gwb_yearly_status.gys_id)))
             LEFT JOIN public.classification_type ON ((gw_chemical_status.clst_id = classification_type.cls_id)))
             LEFT JOIN public.waarde_bepalings_methode_type ON ((waarde_bepalings_methode_type.wbpm_id = gw_chemical_status.wbpm_id)))
          WHERE ((hdo_gwb.wkrv_id = 13) AND (gwb_yearly_status.year_of_status = ANY (ARRAY[2014, 2015])) AND (gw_chemical_status.opt_id > 4400) AND (gw_chemical_status.opt_id <> ALL (ARRAY[4495, 4494, 4487])))
        UNION ALL
         SELECT hdo_gwb.hdo_id AS gwb_id,
            gwb_yearly_status.year_of_status AS jaar,
            gw_quantity_status.opt_id,
            classification_type.description AS oordeel,
            waarde_bepalings_methode_type.code AS wbpm
           FROM ((((public.gwb_yearly_status
             LEFT JOIN public.hydro_object hdo_gwb ON ((hdo_gwb.hdo_id = gwb_yearly_status.gwb_id)))
             JOIN public.gw_quantity_status ON ((gw_quantity_status.gys_id = gwb_yearly_status.gys_id)))
             LEFT JOIN public.classification_type ON ((gw_quantity_status.gwst_id = classification_type.cls_id)))
             LEFT JOIN public.waarde_bepalings_methode_type ON ((waarde_bepalings_methode_type.wbpm_id = gw_quantity_status.wbpm_id)))
          WHERE ((hdo_gwb.wkrv_id = 13) AND (gwb_yearly_status.year_of_status = ANY (ARRAY[2014, 2015])) AND (gw_quantity_status.opt_id > 4400) AND (gw_quantity_status.opt_id <> ALL (ARRAY[4495, 4494, 4487])))
  ORDER BY 1, 2, 3
        ), gwb_oordeel_subt AS (
         SELECT DISTINCT ON (gwb_oordeel_sub.gwb_id, gwb_oordeel_sub.opt_id) gwb_oordeel_sub.gwb_id,
            gwb_oordeel_sub.jaar,
            gwb_oordeel_sub.opt_id,
            gwb_oordeel_sub.oordeel
           FROM gwb_oordeel_sub
          ORDER BY gwb_oordeel_sub.gwb_id, gwb_oordeel_sub.opt_id, gwb_oordeel_sub.jaar DESC, gwb_oordeel_sub.wbpm
        )
 SELECT hydro_object.hdo_id AS db_id,
    hydro_object.inspire_id_local_id AS "euGroundWaterBodyCode",
        CASE gwb_oordeel_subt.opt_id
            WHEN 4486 THEN 'General water quality assessment'::text
            WHEN 4491 THEN 'Drinking Water Protected Area'::text
            WHEN 4492 THEN 'Surface water'::text
            WHEN 4493 THEN 'Groundwater dependent terrestial ecosystems'::text
            WHEN 4498 THEN 'Saline or other intrusion'::text
            ELSE 'oeps, foutje'::text
        END AS "gwChemicalReasonsForFailure"
   FROM ((public.hydro_object
     JOIN gwb_oordeel ON (((gwb_oordeel.gwb_id = hydro_object.hdo_id) AND ((gwb_oordeel.oordeel)::text = 'Ontoereikend'::text) AND (gwb_oordeel.opt_id = 4494))))
     JOIN gwb_oordeel_subt ON (((gwb_oordeel_subt.gwb_id = hydro_object.hdo_id) AND ((gwb_oordeel_subt.oordeel)::text = 'Ontoereikend'::text) AND (gwb_oordeel_subt.opt_id = ANY (ARRAY[4486, 4491, 4492, 4493, 4498])))))
  WHERE (((hydro_object.hydro_object_type)::text = 'GroundWaterBody'::text) AND (hydro_object.wkrv_id = 13))
  ORDER BY hydro_object.inspire_id_local_id, gwb_oordeel_subt.opt_id;


--
-- Name: vw_groundwaterbody_gwquantitativeexemptionpressure; Type: VIEW; Schema: wfd_reporting; Owner: -
--

CREATE VIEW vw_groundwaterbody_gwquantitativeexemptionpressure AS
 WITH gwb_oordeel AS (
         SELECT DISTINCT ON (hdo_gwb.hdo_id, gw_quantity_status.opt_id) hdo_gwb.hdo_id AS gwb_id,
            hdo_gwb.inspire_id_local_id,
            gwb_yearly_status.year_of_status AS jaar,
            gw_quantity_status.opt_id,
            classification_type.description AS oordeel,
            waarde_bepalings_methode_type.code AS wbpm
           FROM ((((public.gwb_yearly_status
             LEFT JOIN public.hydro_object hdo_gwb ON ((hdo_gwb.hdo_id = gwb_yearly_status.gwb_id)))
             JOIN public.gw_quantity_status ON ((gw_quantity_status.gys_id = gwb_yearly_status.gys_id)))
             LEFT JOIN public.classification_type ON ((gw_quantity_status.gwst_id = classification_type.cls_id)))
             LEFT JOIN public.waarde_bepalings_methode_type ON ((waarde_bepalings_methode_type.wbpm_id = gw_quantity_status.wbpm_id)))
          WHERE ((hdo_gwb.wkrv_id = 13) AND (gwb_yearly_status.year_of_status = ANY (ARRAY[2014, 2015])) AND ((classification_type.description)::text = 'Ontoereikend'::text))
          ORDER BY hdo_gwb.hdo_id, gw_quantity_status.opt_id, waarde_bepalings_methode_type.code DESC
        ), pressures AS (
         SELECT DISTINCT ON (hydro_object.hdo_id, spe.eu_xsd) hydro_object.hdo_id AS db_id,
            hydro_object.inspire_id_local_id AS "euGroundWaterBodyCode",
                CASE
                    WHEN (spe.eu_xsd IS NULL) THEN 'No significant pressure'::text
                    ELSE spe.eu_xsd
                END AS "gwSignificantPressureType"
           FROM ((public.hydro_object
             LEFT JOIN public.gwb_pressure ON ((hydro_object.hdo_id = gwb_pressure.gwb_id)))
             LEFT JOIN significant_pressure_enum spe ON ((spe.gw_p_id = gwb_pressure.gprs_id)))
          WHERE ((gwb_pressure.is_significant = true) AND (hydro_object.wkrv_id = 13))
          ORDER BY hydro_object.hdo_id, spe.eu_xsd
        )
 SELECT DISTINCT ON (gwb_oordeel.gwb_id, gwce.obex_id) gwb_oordeel.inspire_id_local_id AS "euGroundWaterBodyCode",
    pressures."gwSignificantPressureType" AS "gwQuantitativeExemptionPressure"
   FROM ((((((((gwb_oordeel
     LEFT JOIN public.gwb_chemical_exemption gwce ON ((gwce.gwb_id = gwb_oordeel.gwb_id)))
     LEFT JOIN public.gwb_chem_exemp_pollutant gce ON ((gce.gwce_id = gwce.gwce_id)))
     LEFT JOIN public.observed_property_type ON ((observed_property_type.opt_id = gwb_oordeel.opt_id)))
     LEFT JOIN pressures ON ((gwb_oordeel.gwb_id = pressures.db_id)))
     LEFT JOIN public.substance_group_element sge ON ((sge.ssge_id = observed_property_type.substance_group_id)))
     LEFT JOIN public.chemische_stof_type chs ON ((chs.chs_id = sge.chs_id)))
     LEFT JOIN public.grootheid_type grh ON ((grh.grh_id = observed_property_type.quantity_id)))
     LEFT JOIN public.objectives_exemption_type ON ((objectives_exemption_type.obex_id = gwce.obex_id)))
  WHERE ((gce.opt_id = ANY (ARRAY[4488, 4489, 4490, 4497])) AND (gwce.obex_id IS NOT NULL))
  ORDER BY gwb_oordeel.gwb_id, gwce.obex_id;


--
-- Name: vw_groundwaterbody_gwquantitativeexemptiontype; Type: VIEW; Schema: wfd_reporting; Owner: -
--

CREATE VIEW vw_groundwaterbody_gwquantitativeexemptiontype AS
 WITH gwb_oordeel AS (
         SELECT DISTINCT ON (hdo_gwb.hdo_id, gw_quantity_status.opt_id) hdo_gwb.hdo_id AS gwb_id,
            hdo_gwb.inspire_id_local_id,
            gwb_yearly_status.year_of_status AS jaar,
            gw_quantity_status.opt_id,
            classification_type.description AS oordeel,
            waarde_bepalings_methode_type.code AS wbpm
           FROM ((((public.gwb_yearly_status
             LEFT JOIN public.hydro_object hdo_gwb ON ((hdo_gwb.hdo_id = gwb_yearly_status.gwb_id)))
             JOIN public.gw_quantity_status ON ((gw_quantity_status.gys_id = gwb_yearly_status.gys_id)))
             LEFT JOIN public.classification_type ON ((gw_quantity_status.gwst_id = classification_type.cls_id)))
             LEFT JOIN public.waarde_bepalings_methode_type ON ((waarde_bepalings_methode_type.wbpm_id = gw_quantity_status.wbpm_id)))
          WHERE ((hdo_gwb.wkrv_id = 13) AND (gwb_yearly_status.year_of_status = ANY (ARRAY[2014, 2015])) AND ((classification_type.description)::text = 'Ontoereikend'::text))
          ORDER BY hdo_gwb.hdo_id, gw_quantity_status.opt_id, waarde_bepalings_methode_type.code DESC
        )
 SELECT DISTINCT ON (gwb_oordeel.gwb_id, gwce.obex_id) gwb_oordeel.inspire_id_local_id AS "euGroundWaterBodyCode",
        CASE
            WHEN (objectives_exemption_type.description IS NULL) THEN 'No exemption'::text
            ELSE objectives_exemption_type.description
        END AS "gwQuantitativeExemptionType"
   FROM (((((((gwb_oordeel
     LEFT JOIN public.gwb_chemical_exemption gwce ON ((gwce.gwb_id = gwb_oordeel.gwb_id)))
     LEFT JOIN public.gwb_chem_exemp_pollutant gce ON ((gce.gwce_id = gwce.gwce_id)))
     LEFT JOIN public.observed_property_type ON ((observed_property_type.opt_id = gwb_oordeel.opt_id)))
     LEFT JOIN public.substance_group_element sge ON ((sge.ssge_id = observed_property_type.substance_group_id)))
     LEFT JOIN public.chemische_stof_type chs ON ((chs.chs_id = sge.chs_id)))
     LEFT JOIN public.grootheid_type grh ON ((grh.grh_id = observed_property_type.quantity_id)))
     LEFT JOIN public.objectives_exemption_type ON ((objectives_exemption_type.obex_id = gwce.obex_id)))
  WHERE ((gce.opt_id IS NULL) OR (gce.opt_id = ANY (ARRAY[4488, 4489, 4490, 4497])))
  ORDER BY gwb_oordeel.gwb_id, gwce.obex_id;


--
-- Name: vw_groundwaterbody_gwquantitativereasonsforfailure; Type: VIEW; Schema: wfd_reporting; Owner: -
--

CREATE VIEW vw_groundwaterbody_gwquantitativereasonsforfailure AS
 WITH gwb_oordeel AS (
         SELECT hdo_gwb.hdo_id AS gwb_id,
            gwb_yearly_status.year_of_status AS jaar,
            gw_chemical_status.opt_id,
            classification_type.description AS oordeel,
            waarde_bepalings_methode_type.code AS wbpm
           FROM ((((public.gwb_yearly_status
             LEFT JOIN public.hydro_object hdo_gwb ON ((hdo_gwb.hdo_id = gwb_yearly_status.gwb_id)))
             JOIN public.gw_chemical_status ON ((gw_chemical_status.gys_id = gwb_yearly_status.gys_id)))
             LEFT JOIN public.classification_type ON ((gw_chemical_status.clst_id = classification_type.cls_id)))
             LEFT JOIN public.waarde_bepalings_methode_type ON ((waarde_bepalings_methode_type.wbpm_id = gw_chemical_status.wbpm_id)))
          WHERE ((hdo_gwb.wkrv_id = 13) AND (gwb_yearly_status.year_of_status = ANY (ARRAY[2014, 2015])) AND ((waarde_bepalings_methode_type.code)::text = 'GWPROTNL'::text) AND (gw_chemical_status.opt_id = ANY (ARRAY[4495, 4494])))
        UNION ALL
         SELECT hdo_gwb.hdo_id AS gwb_id,
            gwb_yearly_status.year_of_status AS jaar,
            gw_quantity_status.opt_id,
            classification_type.description AS oordeel,
            waarde_bepalings_methode_type.code AS wbpm
           FROM ((((public.gwb_yearly_status
             LEFT JOIN public.hydro_object hdo_gwb ON ((hdo_gwb.hdo_id = gwb_yearly_status.gwb_id)))
             JOIN public.gw_quantity_status ON ((gw_quantity_status.gys_id = gwb_yearly_status.gys_id)))
             LEFT JOIN public.classification_type ON ((gw_quantity_status.gwst_id = classification_type.cls_id)))
             LEFT JOIN public.waarde_bepalings_methode_type ON ((waarde_bepalings_methode_type.wbpm_id = gw_quantity_status.wbpm_id)))
          WHERE ((hdo_gwb.wkrv_id = 13) AND (gwb_yearly_status.year_of_status = ANY (ARRAY[2014, 2015])) AND ((waarde_bepalings_methode_type.code)::text = 'GWPROTNL'::text) AND (gw_quantity_status.opt_id = ANY (ARRAY[4495, 4494])))
        ), gwb_oordeel_sub AS (
         SELECT hdo_gwb.hdo_id AS gwb_id,
            gwb_yearly_status.year_of_status AS jaar,
            gw_chemical_status.opt_id,
            classification_type.description AS oordeel,
            waarde_bepalings_methode_type.code AS wbpm
           FROM ((((public.gwb_yearly_status
             LEFT JOIN public.hydro_object hdo_gwb ON ((hdo_gwb.hdo_id = gwb_yearly_status.gwb_id)))
             JOIN public.gw_chemical_status ON ((gw_chemical_status.gys_id = gwb_yearly_status.gys_id)))
             LEFT JOIN public.classification_type ON ((gw_chemical_status.clst_id = classification_type.cls_id)))
             LEFT JOIN public.waarde_bepalings_methode_type ON ((waarde_bepalings_methode_type.wbpm_id = gw_chemical_status.wbpm_id)))
          WHERE ((hdo_gwb.wkrv_id = 13) AND (gwb_yearly_status.year_of_status = ANY (ARRAY[2014, 2015])) AND (gw_chemical_status.opt_id > 4400) AND (gw_chemical_status.opt_id <> ALL (ARRAY[4495, 4494, 4487])))
        UNION ALL
         SELECT hdo_gwb.hdo_id AS gwb_id,
            gwb_yearly_status.year_of_status AS jaar,
            gw_quantity_status.opt_id,
            classification_type.description AS oordeel,
            waarde_bepalings_methode_type.code AS wbpm
           FROM ((((public.gwb_yearly_status
             LEFT JOIN public.hydro_object hdo_gwb ON ((hdo_gwb.hdo_id = gwb_yearly_status.gwb_id)))
             JOIN public.gw_quantity_status ON ((gw_quantity_status.gys_id = gwb_yearly_status.gys_id)))
             LEFT JOIN public.classification_type ON ((gw_quantity_status.gwst_id = classification_type.cls_id)))
             LEFT JOIN public.waarde_bepalings_methode_type ON ((waarde_bepalings_methode_type.wbpm_id = gw_quantity_status.wbpm_id)))
          WHERE ((hdo_gwb.wkrv_id = 13) AND (gwb_yearly_status.year_of_status = ANY (ARRAY[2014, 2015])) AND (gw_quantity_status.opt_id > 4400) AND (gw_quantity_status.opt_id <> ALL (ARRAY[4495, 4494, 4487])))
  ORDER BY 1, 2, 3
        ), gwb_oordeel_subt AS (
         SELECT DISTINCT ON (gwb_oordeel_sub.gwb_id, gwb_oordeel_sub.opt_id) gwb_oordeel_sub.gwb_id,
            gwb_oordeel_sub.jaar,
            gwb_oordeel_sub.opt_id,
            gwb_oordeel_sub.oordeel
           FROM gwb_oordeel_sub
          ORDER BY gwb_oordeel_sub.gwb_id, gwb_oordeel_sub.opt_id, gwb_oordeel_sub.jaar DESC, gwb_oordeel_sub.wbpm
        )
 SELECT hydro_object.hdo_id AS db_id,
    hydro_object.inspire_id_local_id AS "euGroundWaterBodyCode",
        CASE gwb_oordeel_subt.opt_id
            WHEN 4490 THEN 'Saline or intrusions'::text
            WHEN 4488 THEN 'Surface water'::text
            WHEN 4489 THEN 'Groundwater dependent terrestial ecosystems'::text
            WHEN 4497 THEN 'Water balance'::text
            ELSE 'oeps, foutje'::text
        END AS "gwQuantitativeReasonsForFailure"
   FROM ((public.hydro_object
     JOIN gwb_oordeel ON (((gwb_oordeel.gwb_id = hydro_object.hdo_id) AND ((gwb_oordeel.oordeel)::text = 'Ontoereikend'::text) AND (gwb_oordeel.opt_id = 4495))))
     JOIN gwb_oordeel_subt ON (((gwb_oordeel_subt.gwb_id = hydro_object.hdo_id) AND ((gwb_oordeel_subt.oordeel)::text = 'Ontoereikend'::text) AND (gwb_oordeel_subt.opt_id = ANY (ARRAY[4488, 4489, 4490, 4497])))))
  WHERE (((hydro_object.hydro_object_type)::text = 'GroundWaterBody'::text) AND (hydro_object.wkrv_id = 13))
  ORDER BY hydro_object.inspire_id_local_id, gwb_oordeel_subt.opt_id;


--
-- Name: vw_groundwaterbody_gwsignificantimpacttype; Type: VIEW; Schema: wfd_reporting; Owner: -
--

CREATE VIEW vw_groundwaterbody_gwsignificantimpacttype AS
 WITH gwb_oordeel_all AS (
         SELECT hdo_gwb.hdo_id AS gwb_id,
            hdo_gwb.inspire_id_local_id,
            gwb_yearly_status.year_of_status AS jaar,
            classification_type.description AS oordeel,
            waarde_bepalings_methode_type.code AS wbpm
           FROM (((((public.gwb_yearly_status
             LEFT JOIN public.hydro_object hdo_gwb ON ((hdo_gwb.hdo_id = gwb_yearly_status.gwb_id)))
             JOIN public.gw_chemical_status ON ((gw_chemical_status.gys_id = gwb_yearly_status.gys_id)))
             LEFT JOIN public.classification_type ON ((gw_chemical_status.clst_id = classification_type.cls_id)))
             LEFT JOIN public.vw_waargenomen_eigenschap ON ((vw_waargenomen_eigenschap."DB_ID" = gw_chemical_status.opt_id)))
             LEFT JOIN public.waarde_bepalings_methode_type ON ((waarde_bepalings_methode_type.wbpm_id = gw_chemical_status.wbpm_id)))
          WHERE ((hdo_gwb.wkrv_id = 13) AND (gwb_yearly_status.year_of_status = ANY (ARRAY[2014, 2015])) AND ((waarde_bepalings_methode_type.code)::text = 'GWPROTNL'::text) AND (gw_chemical_status.opt_id = ANY (ARRAY[4495, 4494])))
        UNION ALL
         SELECT hdo_gwb.hdo_id AS gwb_id,
            hdo_gwb.inspire_id_local_id,
            gwb_yearly_status.year_of_status AS jaar,
            classification_type.description AS oordeel,
            waarde_bepalings_methode_type.code AS wbpm
           FROM (((((public.gwb_yearly_status
             LEFT JOIN public.hydro_object hdo_gwb ON ((hdo_gwb.hdo_id = gwb_yearly_status.gwb_id)))
             JOIN public.gw_quantity_status ON ((gw_quantity_status.gys_id = gwb_yearly_status.gys_id)))
             LEFT JOIN public.classification_type ON ((gw_quantity_status.gwst_id = classification_type.cls_id)))
             LEFT JOIN public.vw_waargenomen_eigenschap ON ((vw_waargenomen_eigenschap."DB_ID" = gw_quantity_status.opt_id)))
             LEFT JOIN public.waarde_bepalings_methode_type ON ((waarde_bepalings_methode_type.wbpm_id = gw_quantity_status.wbpm_id)))
          WHERE ((hdo_gwb.wkrv_id = 13) AND (gwb_yearly_status.year_of_status = ANY (ARRAY[2014, 2015])) AND ((waarde_bepalings_methode_type.code)::text = 'GWPROTNL'::text) AND (gw_quantity_status.opt_id = ANY (ARRAY[4495, 4494])))
        ), gwb_oordeel AS (
         SELECT DISTINCT ON (gwb_oordeel_all.gwb_id) gwb_oordeel_all.gwb_id,
            gwb_oordeel_all.inspire_id_local_id,
            gwb_oordeel_all.jaar,
            gwb_oordeel_all.oordeel,
            gwb_oordeel_all.wbpm
           FROM gwb_oordeel_all
          ORDER BY gwb_oordeel_all.gwb_id, gwb_oordeel_all.oordeel DESC
        )
 SELECT DISTINCT ON (hydro_object.hdo_id, ipe.eu_xsd) hydro_object.hdo_id AS db_id,
    hydro_object.inspire_id_local_id AS "euGroundWaterBodyCode",
        CASE
            WHEN (ipe.eu_xsd IS NULL) THEN
            CASE
                WHEN ((gwb_oordeel.oordeel)::text = 'Goed'::text) THEN 'NOSI - No significant impact'::text
                ELSE 'UNKN - Unknown impact type'::text
            END
            ELSE ipe.eu_xsd
        END AS "gwSignificantImpactType"
   FROM ((((public.hydro_object
     LEFT JOIN public.gwb_pressure ON (((hydro_object.hdo_id = gwb_pressure.gwb_id) AND (gwb_pressure.is_significant = true))))
     LEFT JOIN public.gwb_pressure_impact ON ((gwb_pressure.gwbp_id = gwb_pressure_impact.gwbp_id)))
     LEFT JOIN significant_impact_enum ipe ON ((ipe.i_id = gwb_pressure_impact.impact_id)))
     LEFT JOIN gwb_oordeel ON ((gwb_oordeel.gwb_id = hydro_object.hdo_id)))
  WHERE ((hydro_object.wkrv_id = 13) AND ((hydro_object.hydro_object_type)::text = 'GroundWaterBody'::text))
  ORDER BY hydro_object.hdo_id, ipe.eu_xsd;


--
-- Name: vw_groundwaterbody_gwsignificantpressuretype; Type: VIEW; Schema: wfd_reporting; Owner: -
--

CREATE VIEW vw_groundwaterbody_gwsignificantpressuretype AS
 WITH bel_aant AS (
         SELECT hydro_object_1.hdo_id AS db_id,
            count(spe_1.eu_xsd) AS aant
           FROM ((public.hydro_object hydro_object_1
             LEFT JOIN public.gwb_pressure gwb_pressure_1 ON ((hydro_object_1.hdo_id = gwb_pressure_1.gwb_id)))
             LEFT JOIN significant_pressure_enum spe_1 ON (((spe_1.gw_p_id = gwb_pressure_1.gprs_id) AND (gwb_pressure_1.is_significant = true))))
          GROUP BY hydro_object_1.hdo_id, hydro_object_1.wkrv_id, hydro_object_1.hydro_object_type
         HAVING ((hydro_object_1.wkrv_id = 13) AND ((hydro_object_1.hydro_object_type)::text = 'GroundWaterBody'::text))
        )
 SELECT DISTINCT ON (hydro_object.inspire_id_local_id, spe.eu_xsd) hydro_object.hdo_id AS db_id,
    hydro_object.inspire_id_local_id AS "euGroundWaterBodyCode",
        CASE
            WHEN (spe.eu_xsd IS NULL) THEN 'No significant pressure'::text
            ELSE spe.eu_xsd
        END AS "gwSignificantPressureType"
   FROM (((public.hydro_object
     LEFT JOIN public.gwb_pressure ON ((hydro_object.hdo_id = gwb_pressure.gwb_id)))
     LEFT JOIN significant_pressure_enum spe ON (((spe.gw_p_id = gwb_pressure.gprs_id) AND (gwb_pressure.is_significant = true))))
     LEFT JOIN bel_aant ON ((bel_aant.db_id = hydro_object.hdo_id)))
  WHERE ((hydro_object.wkrv_id = 13) AND ((hydro_object.hydro_object_type)::text = 'GroundWaterBody'::text) AND (((bel_aant.aant = 0) AND (spe.eu_xsd IS NULL)) OR ((bel_aant.aant > 0) AND (spe.eu_xsd IS NOT NULL))))
  ORDER BY hydro_object.inspire_id_local_id, spe.eu_xsd;


--
-- Name: vw_gwassociatedprotectedarea; Type: VIEW; Schema: wfd_reporting; Owner: -
--

CREATE VIEW vw_gwassociatedprotectedarea AS
 WITH gwb_oordeel_dc AS (
         SELECT hdo_gwb.hdo_id AS gwb_id,
            gwb_yearly_status.year_of_status AS jaar,
            gw_quantity_status.opt_id,
            classification_type.description AS oordeel,
            waarde_bepalings_methode_type.code AS wbpm
           FROM (((((public.gwb_yearly_status
             LEFT JOIN public.hydro_object hdo_gwb ON ((hdo_gwb.hdo_id = gwb_yearly_status.gwb_id)))
             JOIN public.gw_quantity_status ON ((gw_quantity_status.gys_id = gwb_yearly_status.gys_id)))
             LEFT JOIN public.classification_type ON ((gw_quantity_status.gwst_id = classification_type.cls_id)))
             LEFT JOIN public.vw_waargenomen_eigenschap ON ((vw_waargenomen_eigenschap."DB_ID" = gw_quantity_status.opt_id)))
             LEFT JOIN public.waarde_bepalings_methode_type ON ((waarde_bepalings_methode_type.wbpm_id = gw_quantity_status.wbpm_id)))
          WHERE ((hdo_gwb.wkrv_id = 13) AND (gwb_yearly_status.year_of_status = ANY (ARRAY[2014, 2015])) AND (gw_quantity_status.opt_id = ANY (ARRAY[4489])))
        ), gwb_oordeel_dq AS (
         SELECT hdo_gwb.hdo_id AS gwb_id,
            gwb_yearly_status.year_of_status AS jaar,
            gw_chemical_status.opt_id,
            classification_type.description AS oordeel,
            waarde_bepalings_methode_type.code AS wbpm
           FROM (((((public.gwb_yearly_status
             LEFT JOIN public.hydro_object hdo_gwb ON ((hdo_gwb.hdo_id = gwb_yearly_status.gwb_id)))
             JOIN public.gw_chemical_status ON ((gw_chemical_status.gys_id = gwb_yearly_status.gys_id)))
             LEFT JOIN public.classification_type ON ((gw_chemical_status.clst_id = classification_type.cls_id)))
             LEFT JOIN public.vw_waargenomen_eigenschap ON ((vw_waargenomen_eigenschap."DB_ID" = gw_chemical_status.opt_id)))
             LEFT JOIN public.waarde_bepalings_methode_type ON ((waarde_bepalings_methode_type.wbpm_id = gw_chemical_status.wbpm_id)))
          WHERE ((hdo_gwb.wkrv_id = 13) AND (gwb_yearly_status.year_of_status = ANY (ARRAY[2014, 2015])) AND (gw_chemical_status.opt_id = ANY (ARRAY[4493])))
        ), gwb_oordeel_d AS (
         SELECT gwb_oordeel_dc.gwb_id,
            gwb_oordeel_dc.jaar,
            gwb_oordeel_dc.opt_id,
            gwb_oordeel_dc.oordeel AS oordeel_dc,
            gwb_oordeel_dq.oordeel AS oordeel_dq
           FROM (gwb_oordeel_dc
             LEFT JOIN gwb_oordeel_dq ON ((gwb_oordeel_dc.gwb_id = gwb_oordeel_dq.gwb_id)))
        ), gwb_oordeel_b AS (
         SELECT gwn.wpa_id,
            gwb.hdo_id,
            gwn.cls_id,
            gwn.opt_id
           FROM ((public.gw_n2000_status gwn
             JOIN public.gwb_yearly_status gys ON ((gwn.gwsy = gys.gys_id)))
             JOIN public.hydro_object gwb ON (((gwb.hdo_id = gys.gwb_id) AND ((gwb.hydro_object_type)::text = 'GroundWaterBody'::text) AND (gwb.wkrv_id = 13))))
          WHERE (gys.year_of_status = ANY (ARRAY[2014, 2015]))
        )
 SELECT gwb.hdo_id,
    wpa.inspire_id_local_id AS "euProtectedAreaCode",
    gwb.inspire_id_local_id AS "euGroundWaterBodyCode",
        CASE protected_area_type.code
            WHEN 'HA'::text THEN 'Habitats'::text
            WHEN 'BI'::text THEN 'Birds'::text
            ELSE 'oeps'::text
        END AS "protectedAreaType",
    'Dynamically / hydrologically connected with Protected Area'::text AS "protectedAreaAssociationType",
        CASE
            WHEN ((gob.cls_id = 9) OR (gob.cls_id = 8)) THEN 'Yes, some specific water objectives have been set to protect dependent habitats and species but work is still on-going to determine needs.'::text
            ELSE NULL::text
        END AS "protectedAreaHabitatsBirdsObjectivesSet",
        CASE
            WHEN (gob.cls_id = 9) THEN 'No'::text
            ELSE
            CASE
                WHEN (gob.cls_id = 8) THEN 'Yes'::text
                ELSE NULL::text
            END
        END AS "protectedAreaHabitatsBirdsObjectivesMet",
    NULL::text AS "protectedAreaDrinkingWaterObjectivesSet",
    NULL::text AS "protectedAreaDrinkingWaterObjectivesMet",
    NULL::text AS "protectedAreaComment"
   FROM (((((public.waterbody_protected_area_intersection
     JOIN public.wfd_protected_area ON ((waterbody_protected_area_intersection.wpa_id = wfd_protected_area.wpa_id)))
     JOIN public.hydro_object wpa ON ((wpa.hdo_id = wfd_protected_area.wpa_id)))
     JOIN public.hydro_object gwb ON ((waterbody_protected_area_intersection.wbd_id = gwb.hdo_id)))
     JOIN public.protected_area_type ON ((protected_area_type.pat_id = wfd_protected_area.protected_area_type_id)))
     LEFT JOIN gwb_oordeel_b gob ON (((gob.wpa_id = wpa.hdo_id) AND (gob.hdo_id = gwb.hdo_id))))
  WHERE ((gwb.wkrv_id = 13) AND ((gwb.hydro_object_type)::text = 'GroundWaterBody'::text) AND (protected_area_type.gw_type = true))
UNION ALL
 SELECT gwb.hdo_id,
    gwb.inspire_id_local_id AS "euProtectedAreaCode",
    gwb.inspire_id_local_id AS "euGroundWaterBodyCode",
    'Article 7 Abstraction for drinking water'::text AS "protectedAreaType",
    'Within Protected Area'::text AS "protectedAreaAssociationType",
    NULL::text AS "protectedAreaHabitatsBirdsObjectivesSet",
    NULL::text AS "protectedAreaHabitatsBirdsObjectivesMet",
        CASE
            WHEN (((gwb_oordeel_d.oordeel_dc)::text = 'Ontoereikend'::text) OR ((gwb_oordeel_d.oordeel_dc)::text = 'Voldoet'::text) OR ((gwb_oordeel_d.oordeel_dq)::text = 'Ontoereikend'::text) OR ((gwb_oordeel_d.oordeel_dq)::text = 'Voldoet'::text)) THEN 'Yes'::text
            ELSE NULL::text
        END AS "protectedAreaDrinkingWaterObjectivesSet",
        CASE
            WHEN (((gwb_oordeel_d.oordeel_dc)::text = 'Ontoereikend'::text) OR ((gwb_oordeel_d.oordeel_dq)::text = 'Ontoereikend'::text)) THEN 'No'::text
            ELSE
            CASE
                WHEN (((gwb_oordeel_d.oordeel_dc)::text = 'Voldoet'::text) OR ((gwb_oordeel_d.oordeel_dq)::text = 'Voldoet'::text)) THEN 'Yes'::text
                ELSE NULL::text
            END
        END AS "protectedAreaDrinkingWaterObjectivesMet",
    NULL::text AS "protectedAreaComment"
   FROM public.hydro_object gwb,
    public.water_body,
    gwb_oordeel_d
  WHERE ((water_body.wbd_id = gwb.hdo_id) AND (water_body.is_article_7 = true) AND (gwb.wkrv_id = 13) AND ((gwb.hydro_object_type)::text = 'GroundWaterBody'::text) AND (gwb_oordeel_d.gwb_id = gwb.hdo_id))
  ORDER BY 3;


--
-- Name: vw_gwassociatedprotectedarea_protectedareaexemption; Type: VIEW; Schema: wfd_reporting; Owner: -
--

CREATE VIEW vw_gwassociatedprotectedarea_protectedareaexemption AS
 WITH exemption AS (
         SELECT objectives_exemption_type.name,
            objectives_exemption_type.description,
            objectives_exemption_type.article_nr,
            hydro_object.hdo_id,
            hydro_object.inspire_id_local_id,
            gwb_chem_exemp_pollutant.opt_id
           FROM public.objectives_exemption_type,
            public.gwb_chemical_exemption,
            public.hydro_object,
            public.gwb_chem_exemp_pollutant
          WHERE ((gwb_chemical_exemption.obex_id = objectives_exemption_type.obex_id) AND (hydro_object.hdo_id = gwb_chemical_exemption.gwb_id) AND (gwb_chem_exemp_pollutant.gwce_id = gwb_chemical_exemption.gwce_id) AND (gwb_chem_exemp_pollutant.opt_id = ANY (ARRAY[4489, 4493])))
        ), gwb_oordeel_b AS (
         SELECT gwn.wpa_id,
            gwb.hdo_id,
            gwn.cls_id,
            gwn.opt_id
           FROM ((public.gw_n2000_status gwn
             JOIN public.gwb_yearly_status gys ON ((gwn.gwsy = gys.gys_id)))
             JOIN public.hydro_object gwb ON (((gwb.hdo_id = gys.gwb_id) AND ((gwb.hydro_object_type)::text = 'GroundWaterBody'::text) AND (gwb.wkrv_id = 13))))
          WHERE (gys.year_of_status = ANY (ARRAY[2014, 2015]))
        ), exemptions AS (
         SELECT wpa.inspire_id_local_id AS "euProtectedAreaCode",
                CASE
                    WHEN (gob.cls_id = 9) THEN exemption.description
                    ELSE 'No exemption'::text
                END AS "protectedAreaExemption",
                CASE
                    WHEN (gob.cls_id = 9) THEN 1
                    ELSE 2
                END AS volgorde
           FROM ((((((public.waterbody_protected_area_intersection
             JOIN public.wfd_protected_area ON ((waterbody_protected_area_intersection.wpa_id = wfd_protected_area.wpa_id)))
             JOIN public.hydro_object wpa ON ((wpa.hdo_id = wfd_protected_area.wpa_id)))
             JOIN public.hydro_object gwb ON ((waterbody_protected_area_intersection.wbd_id = gwb.hdo_id)))
             JOIN public.protected_area_type ON ((protected_area_type.pat_id = wfd_protected_area.protected_area_type_id)))
             LEFT JOIN gwb_oordeel_b gob ON (((gob.wpa_id = wpa.hdo_id) AND (gob.hdo_id = gwb.hdo_id))))
             JOIN exemption ON ((exemption.hdo_id = gwb.hdo_id)))
          WHERE ((gwb.wkrv_id = 13) AND ((gwb.hydro_object_type)::text = 'GroundWaterBody'::text) AND (protected_area_type.gw_type = true))
        )
 SELECT DISTINCT ON (exemptions."euProtectedAreaCode", exemptions.volgorde, exemptions."protectedAreaExemption") exemptions."euProtectedAreaCode",
    exemptions."protectedAreaExemption"
   FROM exemptions
  ORDER BY exemptions."euProtectedAreaCode", exemptions.volgorde, exemptions."protectedAreaExemption";


--
-- Name: vw_gwchemicalexemptiontype; Type: VIEW; Schema: wfd_reporting; Owner: -
--

CREATE VIEW vw_gwchemicalexemptiontype AS
 WITH gwb_oordeel_ruw AS (
         SELECT DISTINCT ON (hdo_gwb.hdo_id, gw_chemical_status.opt_id) hdo_gwb.hdo_id AS gwb_id,
            gwb_yearly_status.year_of_status AS jaar,
            gw_chemical_status.opt_id,
            classification_type.description AS oordeel,
            waarde_bepalings_methode_type.code AS wbpm,
            wfd_qe_gwtype.is_backgroundlevelsubstance AS bglevel,
            gwb_yearly_status.gys_id
           FROM (((((public.gwb_yearly_status
             LEFT JOIN public.hydro_object hdo_gwb ON ((hdo_gwb.hdo_id = gwb_yearly_status.gwb_id)))
             JOIN public.gw_chemical_status ON ((gw_chemical_status.gys_id = gwb_yearly_status.gys_id)))
             LEFT JOIN public.classification_type ON ((gw_chemical_status.clst_id = classification_type.cls_id)))
             LEFT JOIN public.waarde_bepalings_methode_type ON ((waarde_bepalings_methode_type.wbpm_id = gw_chemical_status.wbpm_id)))
             LEFT JOIN public.wfd_qe_gwtype ON ((gw_chemical_status.opt_id = wfd_qe_gwtype.opt_id)))
          WHERE ((hdo_gwb.wkrv_id = 13) AND (gwb_yearly_status.year_of_status = ANY (ARRAY[2014, 2015])) AND (gw_chemical_status.opt_id < 4000))
          ORDER BY hdo_gwb.hdo_id, gw_chemical_status.opt_id, waarde_bepalings_methode_type.code DESC
        ), gwb_oordeel AS (
         SELECT DISTINCT ON (gwb_oordeel_ruw.gwb_id, gwb_oordeel_ruw.opt_id) gwb_oordeel_ruw.gwb_id,
            gwb_oordeel_ruw.jaar,
            gwb_oordeel_ruw.opt_id,
            gwb_oordeel_ruw.oordeel,
            gwb_oordeel_ruw.wbpm,
            gwb_oordeel_ruw.bglevel,
            observation.numeric_value
           FROM ((gwb_oordeel_ruw
             LEFT JOIN public.gw_testing_conclusion ON ((gwb_oordeel_ruw.gys_id = gw_testing_conclusion.gys_id)))
             LEFT JOIN public.observation ON (((gw_testing_conclusion.gtcc_id = observation.obs_id) AND (gwb_oordeel_ruw.opt_id = observation.observed_property_type))))
          WHERE (((gwb_oordeel_ruw.oordeel)::text = 'Ontoereikend'::text) OR (observation.numeric_value < (100)::double precision) OR (gwb_oordeel_ruw.bglevel = true))
          ORDER BY gwb_oordeel_ruw.gwb_id, gwb_oordeel_ruw.opt_id, observation.numeric_value
        ), gwb_trend AS (
         SELECT hdo_gwb.hdo_id AS gwb_id,
            gwb_yearly_status.year_of_status AS jaar,
            pollutant_trend.opt_id,
            pollutant_trend.depth_m,
            classification_type.description AS oordeel
           FROM (((public.gwb_yearly_status
             LEFT JOIN public.hydro_object hdo_gwb ON ((hdo_gwb.hdo_id = gwb_yearly_status.gwb_id)))
             JOIN public.pollutant_trend ON ((pollutant_trend.gwys_id = gwb_yearly_status.gys_id)))
             LEFT JOIN public.classification_type ON ((pollutant_trend.cls_id = classification_type.cls_id)))
          WHERE ((hdo_gwb.wkrv_id = 13) AND (gwb_yearly_status.year_of_status = ANY (ARRAY[2014, 2015])) AND (pollutant_trend.opt_id < 4000) AND ((classification_type.description)::text <> ALL (ARRAY[('Niet stijgend'::character varying)::text, ('Niet bepaald'::character varying)::text])))
        ), eu_stoffenlijst AS (
         SELECT chemische_stof_type.chs_id,
            chemische_stof_type.cas_nr,
            chemische_stof_type.naam,
            chemische_stof_type.code,
            chemische_stof_type.d_begin,
            chemische_stof_type.d_eind,
            chemische_stof_type.last_changed_date,
            chemische_stof_type.d_status,
            chemische_stof_type.id,
            eu_stoffenlijst.domeinnaam,
            eu_stoffenlijst.value,
            eu_stoffenlijst.grootheidcode,
            eu_stoffenlijst.parametercode,
            eu_stoffenlijst."swFailingRBSPOther"
           FROM public.chemische_stof_type,
            wfd_reporting.eu_stoffenlijst
          WHERE (((eu_stoffenlijst.parametercode)::text = (chemische_stof_type.code)::text) AND (((eu_stoffenlijst.domeinnaam)::text = 'PS_Enum'::text) OR ((eu_stoffenlijst.domeinnaam)::text = 'AdditionalPollutant_Enum'::text) OR ((eu_stoffenlijst.domeinnaam)::text = 'RBSP_Enum'::text)))
        )
 SELECT DISTINCT ON (gwb_oordeel.gwb_id, gwb_oordeel.opt_id)
        CASE
            WHEN (gwce.gwce_id IS NULL) THEN ((gwb_oordeel.gwb_id)::text || (gwb_oordeel.opt_id)::text)
            ELSE (((gwb_oordeel.gwb_id)::text || (gwb_oordeel.opt_id)::text) || (gwce.gwce_id)::text)
        END AS "gWChemicalExemptionTypeID",
        CASE
            WHEN (objectives_exemption_type.description IS NULL) THEN 'No exemption'::text
            ELSE objectives_exemption_type.description
        END AS "gwChemicalExemptionType",
    ((gwb_oordeel.gwb_id)::text || (gwb_oordeel.opt_id)::text) AS "gWPollutantID",
    "left"((hdo.inspire_id_local_id)::text, 4) AS sgb
   FROM ((((((((((((((((public.hydro_object
     LEFT JOIN gwb_oordeel ON ((gwb_oordeel.gwb_id = hydro_object.hdo_id)))
     LEFT JOIN gwb_trend ON (((gwb_trend.gwb_id = hydro_object.hdo_id) AND (gwb_trend.opt_id = gwb_oordeel.opt_id))))
     LEFT JOIN public.observed_property_type ON ((observed_property_type.opt_id = gwb_oordeel.opt_id)))
     LEFT JOIN public.substance_group_element sge ON ((sge.ssge_id = observed_property_type.substance_group_id)))
     LEFT JOIN public.chemische_stof_type chs ON ((chs.chs_id = sge.chs_id)))
     LEFT JOIN public.grootheid_type grh ON ((grh.grh_id = observed_property_type.quantity_id)))
     LEFT JOIN public.natural_background_levels bglevel ON (((bglevel.gwb_id = hydro_object.hdo_id) AND (gwb_oordeel.opt_id = bglevel.opt_id))))
     LEFT JOIN public.eenheid_type ON ((bglevel.concentration_uom_id = eenheid_type.eenh_id)))
     LEFT JOIN public.observed_property_type opt ON ((opt.opt_id = bglevel.opt_id)))
     LEFT JOIN public.hoedanigheid_type ON ((opt.hoedanigheid_id = hoedanigheid_type.hdh_id)))
     LEFT JOIN public.gwb_chemical_exemption gwce ON ((gwce.gwb_id = gwb_oordeel.gwb_id)))
     LEFT JOIN public.gwb_chem_exemp_pollutant gce ON ((gce.gwce_id = gwce.gwce_id)))
     LEFT JOIN public.objectives_exemption_type ON ((objectives_exemption_type.obex_id = gwce.obex_id)))
     JOIN public.water_body wbd ON ((wbd.wbd_id = gwb_oordeel.gwb_id)))
     JOIN public.river_basin_disrict rbd ON ((rbd.rbd_id = wbd.rbd_id)))
     JOIN public.hydro_object hdo ON ((hdo.hdo_id = rbd.rbd_id)))
  WHERE ((gce.opt_id IS NULL) OR (gce.opt_id < 4000) OR ((gce.opt_id = ANY (ARRAY[4486, 4491, 4492, 4493, 4498])) AND ((hydro_object.hydro_object_type)::text = 'GroundWaterBody'::text) AND (hydro_object.wkrv_id = 13)))
  ORDER BY gwb_oordeel.gwb_id, gwb_oordeel.opt_id, gwce.obex_id;


--
-- Name: vw_gwchemicalexemptiontype_gwchemicalexemptionpressure; Type: VIEW; Schema: wfd_reporting; Owner: -
--

CREATE VIEW vw_gwchemicalexemptiontype_gwchemicalexemptionpressure AS
 WITH gwb_oordeel_ruw AS (
         SELECT DISTINCT ON (hdo_gwb.hdo_id, gw_chemical_status.opt_id) hdo_gwb.hdo_id AS gwb_id,
            gwb_yearly_status.year_of_status AS jaar,
            gw_chemical_status.opt_id,
            classification_type.description AS oordeel,
            waarde_bepalings_methode_type.code AS wbpm,
            wfd_qe_gwtype.is_backgroundlevelsubstance AS bglevel,
            gwb_yearly_status.gys_id
           FROM (((((public.gwb_yearly_status
             LEFT JOIN public.hydro_object hdo_gwb ON ((hdo_gwb.hdo_id = gwb_yearly_status.gwb_id)))
             JOIN public.gw_chemical_status ON ((gw_chemical_status.gys_id = gwb_yearly_status.gys_id)))
             LEFT JOIN public.classification_type ON ((gw_chemical_status.clst_id = classification_type.cls_id)))
             LEFT JOIN public.waarde_bepalings_methode_type ON ((waarde_bepalings_methode_type.wbpm_id = gw_chemical_status.wbpm_id)))
             LEFT JOIN public.wfd_qe_gwtype ON ((gw_chemical_status.opt_id = wfd_qe_gwtype.opt_id)))
          WHERE ((hdo_gwb.wkrv_id = 13) AND (gwb_yearly_status.year_of_status = ANY (ARRAY[2014, 2015])) AND (gw_chemical_status.opt_id < 4000))
          ORDER BY hdo_gwb.hdo_id, gw_chemical_status.opt_id, waarde_bepalings_methode_type.code DESC
        ), gwb_oordeel AS (
         SELECT DISTINCT ON (gwb_oordeel_ruw.gwb_id, gwb_oordeel_ruw.opt_id) gwb_oordeel_ruw.gwb_id,
            gwb_oordeel_ruw.jaar,
            gwb_oordeel_ruw.opt_id,
            gwb_oordeel_ruw.oordeel,
            gwb_oordeel_ruw.wbpm,
            gwb_oordeel_ruw.bglevel,
            observation.numeric_value
           FROM ((gwb_oordeel_ruw
             LEFT JOIN public.gw_testing_conclusion ON ((gwb_oordeel_ruw.gys_id = gw_testing_conclusion.gys_id)))
             LEFT JOIN public.observation ON (((gw_testing_conclusion.gtcc_id = observation.obs_id) AND (gwb_oordeel_ruw.opt_id = observation.observed_property_type))))
          WHERE (((gwb_oordeel_ruw.oordeel)::text = 'Ontoereikend'::text) OR (observation.numeric_value < (100)::double precision) OR (gwb_oordeel_ruw.bglevel = true))
          ORDER BY gwb_oordeel_ruw.gwb_id, gwb_oordeel_ruw.opt_id, observation.numeric_value
        ), gwb_trend AS (
         SELECT hdo_gwb.hdo_id AS gwb_id,
            gwb_yearly_status.year_of_status AS jaar,
            pollutant_trend.opt_id,
            pollutant_trend.depth_m,
            classification_type.description AS oordeel
           FROM (((public.gwb_yearly_status
             LEFT JOIN public.hydro_object hdo_gwb ON ((hdo_gwb.hdo_id = gwb_yearly_status.gwb_id)))
             JOIN public.pollutant_trend ON ((pollutant_trend.gwys_id = gwb_yearly_status.gys_id)))
             LEFT JOIN public.classification_type ON ((pollutant_trend.cls_id = classification_type.cls_id)))
          WHERE ((hdo_gwb.wkrv_id = 13) AND (gwb_yearly_status.year_of_status = ANY (ARRAY[2014, 2015])) AND (pollutant_trend.opt_id < 4000) AND ((classification_type.description)::text <> ALL (ARRAY[('Niet stijgend'::character varying)::text, ('Niet bepaald'::character varying)::text])))
        ), eu_stoffenlijst AS (
         SELECT chemische_stof_type.chs_id,
            chemische_stof_type.cas_nr,
            chemische_stof_type.naam,
            chemische_stof_type.code,
            chemische_stof_type.d_begin,
            chemische_stof_type.d_eind,
            chemische_stof_type.last_changed_date,
            chemische_stof_type.d_status,
            chemische_stof_type.id,
            eu_stoffenlijst.domeinnaam,
            eu_stoffenlijst.value,
            eu_stoffenlijst.grootheidcode,
            eu_stoffenlijst.parametercode,
            eu_stoffenlijst."swFailingRBSPOther"
           FROM public.chemische_stof_type,
            wfd_reporting.eu_stoffenlijst
          WHERE (((eu_stoffenlijst.parametercode)::text = (chemische_stof_type.code)::text) AND (((eu_stoffenlijst.domeinnaam)::text = 'PS_Enum'::text) OR ((eu_stoffenlijst.domeinnaam)::text = 'AdditionalPollutant_Enum'::text) OR ((eu_stoffenlijst.domeinnaam)::text = 'RBSP_Enum'::text)))
        ), pressures AS (
         SELECT DISTINCT ON (hydro_object_1.hdo_id, spe.eu_xsd) hydro_object_1.hdo_id AS db_id,
            hydro_object_1.inspire_id_local_id AS "euGroundWaterBodyCode",
                CASE
                    WHEN (spe.eu_xsd IS NULL) THEN 'No significant pressure'::text
                    ELSE spe.eu_xsd
                END AS "gwSignificantPressureType"
           FROM ((public.hydro_object hydro_object_1
             LEFT JOIN public.gwb_pressure ON ((hydro_object_1.hdo_id = gwb_pressure.gwb_id)))
             LEFT JOIN significant_pressure_enum spe ON ((spe.gw_p_id = gwb_pressure.gprs_id)))
          WHERE ((gwb_pressure.is_significant = true) AND (hydro_object_1.wkrv_id = 13))
          ORDER BY hydro_object_1.hdo_id, spe.eu_xsd
        )
 SELECT DISTINCT ON (gwb_oordeel.gwb_id, gwb_oordeel.opt_id, gwce.obex_id)
        CASE
            WHEN (gwce.gwce_id IS NULL) THEN ((gwb_oordeel.gwb_id)::text || (gwb_oordeel.opt_id)::text)
            ELSE (((gwb_oordeel.gwb_id)::text || (gwb_oordeel.opt_id)::text) || (gwce.gwce_id)::text)
        END AS "gWChemicalExemptionTypeID",
    pressures."gwSignificantPressureType" AS "gwChemicalExemptionPressure"
   FROM (((((((((((((((((public.hydro_object
     LEFT JOIN gwb_oordeel ON ((gwb_oordeel.gwb_id = hydro_object.hdo_id)))
     LEFT JOIN gwb_trend ON (((gwb_trend.gwb_id = hydro_object.hdo_id) AND (gwb_trend.opt_id = gwb_oordeel.opt_id))))
     LEFT JOIN public.observed_property_type ON ((observed_property_type.opt_id = gwb_oordeel.opt_id)))
     LEFT JOIN public.substance_group_element sge ON ((sge.ssge_id = observed_property_type.substance_group_id)))
     LEFT JOIN public.chemische_stof_type chs ON ((chs.chs_id = sge.chs_id)))
     LEFT JOIN public.grootheid_type grh ON ((grh.grh_id = observed_property_type.quantity_id)))
     LEFT JOIN public.natural_background_levels bglevel ON (((bglevel.gwb_id = hydro_object.hdo_id) AND (gwb_oordeel.opt_id = bglevel.opt_id))))
     LEFT JOIN public.eenheid_type ON ((bglevel.concentration_uom_id = eenheid_type.eenh_id)))
     LEFT JOIN public.observed_property_type opt ON ((opt.opt_id = bglevel.opt_id)))
     LEFT JOIN public.hoedanigheid_type ON ((opt.hoedanigheid_id = hoedanigheid_type.hdh_id)))
     LEFT JOIN public.gwb_chemical_exemption gwce ON ((gwce.gwb_id = gwb_oordeel.gwb_id)))
     LEFT JOIN public.gwb_chem_exemp_pollutant gce ON ((gce.gwce_id = gwce.gwce_id)))
     LEFT JOIN public.objectives_exemption_type ON ((objectives_exemption_type.obex_id = gwce.obex_id)))
     JOIN public.water_body wbd ON ((wbd.wbd_id = gwb_oordeel.gwb_id)))
     JOIN public.river_basin_disrict rbd ON ((rbd.rbd_id = wbd.rbd_id)))
     JOIN public.hydro_object hdo ON ((hdo.hdo_id = rbd.rbd_id)))
     LEFT JOIN pressures ON ((gwb_oordeel.gwb_id = pressures.db_id)))
  WHERE (((gce.opt_id IS NULL) OR (gce.opt_id < 4000) OR (gce.opt_id = ANY (ARRAY[4486, 4491, 4492, 4493, 4498]))) AND (gwce.obex_id IS NOT NULL) AND ((hydro_object.hydro_object_type)::text = 'GroundWaterBody'::text) AND (hydro_object.wkrv_id = 13) AND (objectives_exemption_type.description IS NOT NULL))
  ORDER BY gwb_oordeel.gwb_id, gwb_oordeel.opt_id, gwce.obex_id;


--
-- Name: vw_gwexemptions; Type: VIEW; Schema: wfd_reporting; Owner: -
--

CREATE VIEW vw_gwexemptions AS
 SELECT DISTINCT ON (("left"((hdo_rbd2.inspire_id_local_id)::text, 4))) (hdo_rbd2.hdo_id)::text AS "gWExemptionsID",
    "left"((hdo_rbd2.inspire_id_local_id)::text, 4) AS "euRBDCode",
        CASE
            WHEN (gwce.obex_id = 2) THEN 'Yes'::text
            ELSE 'No'::text
        END AS "gwDisproportionateCost",
    'No'::text AS "gwDisproportionateCostOtherEULegislation",
    'No'::text AS "gwExemptionsTransboundary"
   FROM (((((public.hydro_object hdo_rbd2
     LEFT JOIN public.objectives_exemption_type ON ((1 = 1)))
     LEFT JOIN public.gwb_chemical_exemption gwce ON ((objectives_exemption_type.obex_id = gwce.obex_id)))
     LEFT JOIN public.water_body ON ((water_body.wbd_id = gwce.gwb_id)))
     LEFT JOIN public.river_basin_disrict rbd ON ((rbd.rbd_id = water_body.rbd_id)))
     LEFT JOIN public.hydro_object hdo_rbd ON ((rbd.rbd_id = hdo_rbd.hdo_id)))
  WHERE ((hdo_rbd2.wkrv_id = 13) AND ((hdo_rbd2.hydro_object_type)::text = 'RiverBasinDistrict'::text) AND ((hdo_rbd2.inspire_id_local_id)::text ~~ 'NL%'::text) AND (((substr(objectives_exemption_type.description, 8, 4) = '4(4)'::text) AND (gwce.obex_id = 2)) OR (substr(objectives_exemption_type.description, 8, 4) = ANY (ARRAY['4(5)'::text, '4(6)'::text, '4(7)'::text]))))
  ORDER BY ("left"((hdo_rbd2.inspire_id_local_id)::text, 4));


--
-- Name: vw_gwexemptions_gwexemption44driver; Type: VIEW; Schema: wfd_reporting; Owner: -
--

CREATE VIEW vw_gwexemptions_gwexemption44driver AS
 WITH gwb_oordeel AS (
         SELECT DISTINCT ON (hdo_gwb.hdo_id, gw_quantity_status.opt_id) hdo_gwb.hdo_id AS gwb_id,
            gwb_yearly_status.year_of_status AS jaar,
            gw_quantity_status.opt_id,
            classification_type.description AS oordeel,
            waarde_bepalings_methode_type.code AS wbpm
           FROM ((((public.gwb_yearly_status
             LEFT JOIN public.hydro_object hdo_gwb ON ((hdo_gwb.hdo_id = gwb_yearly_status.gwb_id)))
             JOIN public.gw_quantity_status ON ((gw_quantity_status.gys_id = gwb_yearly_status.gys_id)))
             LEFT JOIN public.classification_type ON ((gw_quantity_status.gwst_id = classification_type.cls_id)))
             LEFT JOIN public.waarde_bepalings_methode_type ON ((waarde_bepalings_methode_type.wbpm_id = gw_quantity_status.wbpm_id)))
          WHERE ((hdo_gwb.wkrv_id = 13) AND (gwb_yearly_status.year_of_status = ANY (ARRAY[2014, 2015])) AND ((classification_type.description)::text = 'Ontoereikend'::text))
        UNION ALL
         SELECT DISTINCT ON (hdo_gwb.hdo_id, gw_chemical_status.opt_id) hdo_gwb.hdo_id AS gwb_id,
            gwb_yearly_status.year_of_status AS jaar,
            gw_chemical_status.opt_id,
            classification_type.description AS oordeel,
            waarde_bepalings_methode_type.code AS wbpm
           FROM ((((public.gwb_yearly_status
             LEFT JOIN public.hydro_object hdo_gwb ON ((hdo_gwb.hdo_id = gwb_yearly_status.gwb_id)))
             JOIN public.gw_chemical_status ON ((gw_chemical_status.gys_id = gwb_yearly_status.gys_id)))
             LEFT JOIN public.classification_type ON ((gw_chemical_status.clst_id = classification_type.cls_id)))
             LEFT JOIN public.waarde_bepalings_methode_type ON ((waarde_bepalings_methode_type.wbpm_id = gw_chemical_status.wbpm_id)))
          WHERE ((hdo_gwb.wkrv_id = 13) AND (gwb_yearly_status.year_of_status = ANY (ARRAY[2014, 2015])) AND ((classification_type.description)::text = 'Ontoereikend'::text))
  ORDER BY 1, 3, 4 DESC
        ), gwb_oordeel_i AS (
         SELECT DISTINCT ON (gwb_oordeel_1.gwb_id) gwb_oordeel_1.gwb_id,
            gwb_oordeel_1.opt_id,
            gwb_oordeel_1.jaar,
            gwb_oordeel_1.oordeel,
            gwb_oordeel_1.wbpm
           FROM gwb_oordeel gwb_oordeel_1
          ORDER BY gwb_oordeel_1.gwb_id, gwb_oordeel_1.oordeel DESC
        ), driver AS (
         SELECT hydro_object.hdo_id AS db_id,
            drivers.naam
           FROM (((public.hydro_object
             LEFT JOIN public.gwb_pressure ON (((hydro_object.hdo_id = gwb_pressure.gwb_id) AND (gwb_pressure.is_significant = true))))
             LEFT JOIN public.gw_pressure_type_driver ON ((gwb_pressure.gprs_id = gw_pressure_type_driver.gprs_id)))
             LEFT JOIN domains.drivers ON ((drivers.driver_id = gw_pressure_type_driver.driver_id)))
          WHERE ((hydro_object.wkrv_id = 13) AND ((hydro_object.hydro_object_type)::text = 'GroundWaterBody'::text))
          ORDER BY hydro_object.hdo_id
        ), driver_aant_ruw AS (
         SELECT "left"((hdo_rbd2_1.inspire_id_local_id)::text, 4) AS rbd,
            substr(objectives_exemption_type_1.description, 8, 4) AS art,
            count(driver_1.naam) AS aant
           FROM (((((((public.hydro_object hdo_rbd2_1
             LEFT JOIN public.objectives_exemption_type objectives_exemption_type_1 ON ((1 = 1)))
             LEFT JOIN public.gwb_chemical_exemption gwce_1 ON ((objectives_exemption_type_1.obex_id = gwce_1.obex_id)))
             LEFT JOIN gwb_oordeel gwb_oordeel_1 ON ((gwce_1.gwb_id = gwb_oordeel_1.gwb_id)))
             LEFT JOIN public.water_body water_body_1 ON ((water_body_1.wbd_id = gwb_oordeel_1.gwb_id)))
             LEFT JOIN public.river_basin_disrict rbd_1 ON ((rbd_1.rbd_id = water_body_1.rbd_id)))
             LEFT JOIN public.hydro_object hdo_rbd_1 ON ((rbd_1.rbd_id = hdo_rbd_1.hdo_id)))
             LEFT JOIN driver driver_1 ON ((gwb_oordeel_1.gwb_id = driver_1.db_id)))
          GROUP BY ("left"((hdo_rbd2_1.inspire_id_local_id)::text, 4)), (substr(objectives_exemption_type_1.description, 8, 4)), driver_1.naam, hdo_rbd2_1.wkrv_id, hdo_rbd2_1.hydro_object_type, hdo_rbd2_1.inspire_id_local_id
         HAVING ((hdo_rbd2_1.wkrv_id = 13) AND ((hdo_rbd2_1.hydro_object_type)::text = 'RiverBasinDistrict'::text) AND ((hdo_rbd2_1.inspire_id_local_id)::text ~~ 'NL%'::text))
          ORDER BY ("left"((hdo_rbd2_1.inspire_id_local_id)::text, 4)), (substr(objectives_exemption_type_1.description, 8, 4))
        ), driver_aant AS (
         SELECT DISTINCT ON (driver_aant_ruw.rbd, driver_aant_ruw.art) driver_aant_ruw.rbd,
            driver_aant_ruw.art,
            driver_aant_ruw.aant
           FROM driver_aant_ruw
          ORDER BY driver_aant_ruw.rbd, driver_aant_ruw.art, driver_aant_ruw.aant DESC
        )
 SELECT DISTINCT ON (("left"((hdo_rbd2.inspire_id_local_id)::text, 4)), driver.naam) (hdo_rbd2.hdo_id)::text AS "gWExemptionsID",
        CASE
            WHEN (driver_aant.aant = 0) THEN 'Exemption not applied'::text
            ELSE
            CASE driver.naam
                WHEN 'Landbouw'::text THEN 'Agriculture'::text
                WHEN 'Klimaatverandering'::text THEN 'Climate change'::text
                WHEN 'Energie (hydropower)'::text THEN 'Energy - hydropower'::text
                WHEN 'Energie (geen hydropower)'::text THEN 'Energy - non-hydropower'::text
                WHEN 'Visserij & Aquacultuur'::text THEN 'Fisheries and aquaculture'::text
                WHEN 'Hoogwaterbescherming'::text THEN 'Flood protection'::text
                WHEN 'Bosbouw'::text THEN 'Forestry'::text
                WHEN 'Industrie'::text THEN 'Industry'::text
                WHEN 'Toerisme en Recreatie'::text THEN 'Tourism and recreation'::text
                WHEN 'Transport'::text THEN 'Transport'::text
                WHEN 'Stedelijke ontwikkeling'::text THEN 'Urban development'::text
                WHEN 'Recreatie'::text THEN 'Tourism and recreation'::text
                WHEN 'Niet bekend of verouderd'::text THEN 'Unknown - other'::text
                WHEN 'Eén of meerdere'::text THEN 'Unknown - other'::text
                WHEN 'Anders'::text THEN 'Unknown - other'::text
                ELSE 'oeps'::text
            END
        END AS "gwExemption44Driver"
   FROM ((((((((public.hydro_object hdo_rbd2
     LEFT JOIN public.objectives_exemption_type ON ((1 = 1)))
     LEFT JOIN public.gwb_chemical_exemption gwce ON ((objectives_exemption_type.obex_id = gwce.obex_id)))
     LEFT JOIN gwb_oordeel ON ((gwce.gwb_id = gwb_oordeel.gwb_id)))
     LEFT JOIN public.water_body ON ((water_body.wbd_id = gwb_oordeel.gwb_id)))
     LEFT JOIN public.river_basin_disrict rbd ON ((rbd.rbd_id = water_body.rbd_id)))
     LEFT JOIN public.hydro_object hdo_rbd ON ((rbd.rbd_id = hdo_rbd.hdo_id)))
     LEFT JOIN driver_aant ON ((("left"((hdo_rbd2.inspire_id_local_id)::text, 4) = driver_aant.rbd) AND (driver_aant.art = substr(objectives_exemption_type.description, 8, 4)))))
     LEFT JOIN driver ON ((gwb_oordeel.gwb_id = driver.db_id)))
  WHERE ((hdo_rbd2.wkrv_id = 13) AND ((hdo_rbd2.hydro_object_type)::text = 'RiverBasinDistrict'::text) AND ((hdo_rbd2.inspire_id_local_id)::text ~~ 'NL%'::text) AND (((driver.naam IS NOT NULL) AND (driver_aant.aant > 0)) OR ((driver.naam IS NULL) AND (driver_aant.aant = 0))) AND (substr(objectives_exemption_type.description, 8, 4) = '4(4)'::text))
  ORDER BY ("left"((hdo_rbd2.inspire_id_local_id)::text, 4)), driver.naam;


--
-- Name: vw_gwexemptions_gwexemption44impact; Type: VIEW; Schema: wfd_reporting; Owner: -
--

CREATE VIEW vw_gwexemptions_gwexemption44impact AS
 WITH gwb_oordeel AS (
         SELECT DISTINCT ON (hdo_gwb.hdo_id, gw_quantity_status.opt_id) hdo_gwb.hdo_id AS gwb_id,
            gwb_yearly_status.year_of_status AS jaar,
            gw_quantity_status.opt_id,
            classification_type.description AS oordeel,
            waarde_bepalings_methode_type.code AS wbpm
           FROM ((((public.gwb_yearly_status
             LEFT JOIN public.hydro_object hdo_gwb ON ((hdo_gwb.hdo_id = gwb_yearly_status.gwb_id)))
             JOIN public.gw_quantity_status ON ((gw_quantity_status.gys_id = gwb_yearly_status.gys_id)))
             LEFT JOIN public.classification_type ON ((gw_quantity_status.gwst_id = classification_type.cls_id)))
             LEFT JOIN public.waarde_bepalings_methode_type ON ((waarde_bepalings_methode_type.wbpm_id = gw_quantity_status.wbpm_id)))
          WHERE ((hdo_gwb.wkrv_id = 13) AND (gwb_yearly_status.year_of_status = ANY (ARRAY[2014, 2015])) AND ((classification_type.description)::text = 'Ontoereikend'::text))
        UNION ALL
         SELECT DISTINCT ON (hdo_gwb.hdo_id, gw_chemical_status.opt_id) hdo_gwb.hdo_id AS gwb_id,
            gwb_yearly_status.year_of_status AS jaar,
            gw_chemical_status.opt_id,
            classification_type.description AS oordeel,
            waarde_bepalings_methode_type.code AS wbpm
           FROM ((((public.gwb_yearly_status
             LEFT JOIN public.hydro_object hdo_gwb ON ((hdo_gwb.hdo_id = gwb_yearly_status.gwb_id)))
             JOIN public.gw_chemical_status ON ((gw_chemical_status.gys_id = gwb_yearly_status.gys_id)))
             LEFT JOIN public.classification_type ON ((gw_chemical_status.clst_id = classification_type.cls_id)))
             LEFT JOIN public.waarde_bepalings_methode_type ON ((waarde_bepalings_methode_type.wbpm_id = gw_chemical_status.wbpm_id)))
          WHERE ((hdo_gwb.wkrv_id = 13) AND (gwb_yearly_status.year_of_status = ANY (ARRAY[2014, 2015])) AND ((classification_type.description)::text = 'Ontoereikend'::text))
  ORDER BY 1, 3, 4 DESC
        ), gwb_oordeel_i AS (
         SELECT DISTINCT ON (gwb_oordeel_1.gwb_id) gwb_oordeel_1.gwb_id,
            gwb_oordeel_1.opt_id,
            gwb_oordeel_1.jaar,
            gwb_oordeel_1.oordeel,
            gwb_oordeel_1.wbpm
           FROM gwb_oordeel gwb_oordeel_1
          ORDER BY gwb_oordeel_1.gwb_id, gwb_oordeel_1.oordeel DESC
        ), impact AS (
         SELECT hydro_object.hdo_id AS db_id,
                CASE
                    WHEN (ipe.eu_xsd IS NULL) THEN
                    CASE
                        WHEN ((gwb_oordeel_i.oordeel)::text = 'Goed'::text) THEN 'NOSI - No significant impact'::text
                        ELSE 'UNKN - Unknown impact type'::text
                    END
                    ELSE ipe.eu_xsd
                END AS impact_type
           FROM ((((public.hydro_object
             LEFT JOIN public.gwb_pressure ON (((hydro_object.hdo_id = gwb_pressure.gwb_id) AND (gwb_pressure.is_significant = true))))
             LEFT JOIN public.gwb_pressure_impact ON ((gwb_pressure.gwbp_id = gwb_pressure_impact.gwbp_id)))
             LEFT JOIN significant_impact_enum ipe ON ((ipe.i_id = gwb_pressure_impact.impact_id)))
             LEFT JOIN gwb_oordeel_i ON ((gwb_oordeel_i.gwb_id = hydro_object.hdo_id)))
          WHERE ((hydro_object.wkrv_id = 13) AND ((hydro_object.hydro_object_type)::text = 'GroundWaterBody'::text))
          ORDER BY hydro_object.hdo_id, ipe.eu_xsd
        ), impact_aant_ruw AS (
         SELECT "left"((hdo_rbd2_1.inspire_id_local_id)::text, 4) AS rbd,
            substr(objectives_exemption_type_1.description, 8, 4) AS art,
            count(impact_1.impact_type) AS aant
           FROM (((((((public.hydro_object hdo_rbd2_1
             LEFT JOIN public.objectives_exemption_type objectives_exemption_type_1 ON ((1 = 1)))
             LEFT JOIN public.gwb_chemical_exemption gwce_1 ON ((objectives_exemption_type_1.obex_id = gwce_1.obex_id)))
             LEFT JOIN gwb_oordeel gwb_oordeel_1 ON ((gwce_1.gwb_id = gwb_oordeel_1.gwb_id)))
             LEFT JOIN public.water_body water_body_1 ON ((water_body_1.wbd_id = gwb_oordeel_1.gwb_id)))
             LEFT JOIN public.river_basin_disrict rbd_1 ON ((rbd_1.rbd_id = water_body_1.rbd_id)))
             LEFT JOIN public.hydro_object hdo_rbd_1 ON ((rbd_1.rbd_id = hdo_rbd_1.hdo_id)))
             LEFT JOIN impact impact_1 ON ((gwb_oordeel_1.gwb_id = impact_1.db_id)))
          GROUP BY ("left"((hdo_rbd2_1.inspire_id_local_id)::text, 4)), (substr(objectives_exemption_type_1.description, 8, 4)), impact_1.impact_type, hdo_rbd2_1.wkrv_id, hdo_rbd2_1.hydro_object_type, hdo_rbd2_1.inspire_id_local_id
         HAVING ((hdo_rbd2_1.wkrv_id = 13) AND ((hdo_rbd2_1.hydro_object_type)::text = 'RiverBasinDistrict'::text) AND ((hdo_rbd2_1.inspire_id_local_id)::text ~~ 'NL%'::text))
          ORDER BY ("left"((hdo_rbd2_1.inspire_id_local_id)::text, 4)), (substr(objectives_exemption_type_1.description, 8, 4))
        ), impact_aant AS (
         SELECT DISTINCT ON (impact_aant_ruw.rbd, impact_aant_ruw.art) impact_aant_ruw.rbd,
            impact_aant_ruw.art,
            impact_aant_ruw.aant
           FROM impact_aant_ruw
          ORDER BY impact_aant_ruw.rbd, impact_aant_ruw.art, impact_aant_ruw.aant DESC
        )
 SELECT DISTINCT ON (("left"((hdo_rbd2.inspire_id_local_id)::text, 4)), impact.impact_type) (hdo_rbd2.hdo_id)::text AS "gWExemptionsID",
        CASE
            WHEN (impact_aant.aant = 0) THEN 'Not applicable'::text
            ELSE impact.impact_type
        END AS "gwExemption44Impact"
   FROM ((((((((public.hydro_object hdo_rbd2
     LEFT JOIN public.objectives_exemption_type ON ((1 = 1)))
     LEFT JOIN public.gwb_chemical_exemption gwce ON ((objectives_exemption_type.obex_id = gwce.obex_id)))
     LEFT JOIN gwb_oordeel ON ((gwce.gwb_id = gwb_oordeel.gwb_id)))
     LEFT JOIN public.water_body ON ((water_body.wbd_id = gwb_oordeel.gwb_id)))
     LEFT JOIN public.river_basin_disrict rbd ON ((rbd.rbd_id = water_body.rbd_id)))
     LEFT JOIN public.hydro_object hdo_rbd ON ((rbd.rbd_id = hdo_rbd.hdo_id)))
     LEFT JOIN impact_aant ON ((("left"((hdo_rbd2.inspire_id_local_id)::text, 4) = impact_aant.rbd) AND (impact_aant.art = substr(objectives_exemption_type.description, 8, 4)))))
     LEFT JOIN impact ON ((gwb_oordeel.gwb_id = impact.db_id)))
  WHERE ((hdo_rbd2.wkrv_id = 13) AND ((hdo_rbd2.hydro_object_type)::text = 'RiverBasinDistrict'::text) AND ((hdo_rbd2.inspire_id_local_id)::text ~~ 'NL%'::text) AND (((impact.impact_type IS NOT NULL) AND (impact_aant.aant > 0)) OR ((impact.impact_type IS NULL) AND (impact_aant.aant = 0))) AND (substr(objectives_exemption_type.description, 8, 4) = '4(4)'::text))
  ORDER BY ("left"((hdo_rbd2.inspire_id_local_id)::text, 4)), impact.impact_type;


--
-- Name: vw_gwexemptions_gwexemption45driver; Type: VIEW; Schema: wfd_reporting; Owner: -
--

CREATE VIEW vw_gwexemptions_gwexemption45driver AS
 SELECT DISTINCT ON (hdo_rbd2.hdo_id) (hdo_rbd2.hdo_id || '5'::text) AS "gWExemptionsID",
    'Exemption not applied'::text AS "gwExemption45Driver"
   FROM (((((public.hydro_object hdo_rbd2
     LEFT JOIN public.objectives_exemption_type ON ((1 = 1)))
     LEFT JOIN public.gwb_chemical_exemption gwce ON ((objectives_exemption_type.obex_id = gwce.obex_id)))
     LEFT JOIN public.water_body ON ((water_body.wbd_id = gwce.gwb_id)))
     LEFT JOIN public.river_basin_disrict rbd ON ((rbd.rbd_id = water_body.rbd_id)))
     LEFT JOIN public.hydro_object hdo_rbd ON ((rbd.rbd_id = hdo_rbd.hdo_id)))
  WHERE ((hdo_rbd2.wkrv_id = 13) AND ((hdo_rbd2.hydro_object_type)::text = 'RiverBasinDistrict'::text) AND ((hdo_rbd2.inspire_id_local_id)::text ~~ 'NL%'::text) AND (rbd.international_rbd IS NOT NULL) AND (length((hdo_rbd2.inspire_id_local_id)::text) = 4))
  ORDER BY hdo_rbd2.hdo_id;


--
-- Name: vw_gwexemptions_gwexemption45impact; Type: VIEW; Schema: wfd_reporting; Owner: -
--

CREATE VIEW vw_gwexemptions_gwexemption45impact AS
 SELECT DISTINCT ON (hdo_rbd2.hdo_id) (hdo_rbd2.hdo_id || '5'::text) AS "gWExemptionsID",
    'Not applicable'::text AS "gwExemption45Impact"
   FROM (((((public.hydro_object hdo_rbd2
     LEFT JOIN public.objectives_exemption_type ON ((1 = 1)))
     LEFT JOIN public.gwb_chemical_exemption gwce ON ((objectives_exemption_type.obex_id = gwce.obex_id)))
     LEFT JOIN public.water_body ON ((water_body.wbd_id = gwce.gwb_id)))
     LEFT JOIN public.river_basin_disrict rbd ON ((rbd.rbd_id = water_body.rbd_id)))
     LEFT JOIN public.hydro_object hdo_rbd ON ((rbd.rbd_id = hdo_rbd.hdo_id)))
  WHERE ((hdo_rbd2.wkrv_id = 13) AND ((hdo_rbd2.hydro_object_type)::text = 'RiverBasinDistrict'::text) AND ((hdo_rbd2.inspire_id_local_id)::text ~~ 'NL%'::text) AND (rbd.international_rbd IS NOT NULL) AND (length((hdo_rbd2.inspire_id_local_id)::text) = 4))
  ORDER BY hdo_rbd2.hdo_id;


--
-- Name: vw_gwexemptions_gwexemption46; Type: VIEW; Schema: wfd_reporting; Owner: -
--

CREATE VIEW vw_gwexemptions_gwexemption46 AS
 WITH e46_1 AS (
         SELECT DISTINCT ON (("left"((hdo_rbd2.inspire_id_local_id)::text, 4)), gwce.obex_id) (hdo_rbd2.hdo_id)::text AS "gWExemptionsID",
                CASE
                    WHEN (gwce.obex_id = ANY (ARRAY[4, 5, 6])) THEN 'Yes (prolonged droughts)'::text
                    ELSE 'Article 4(6) has not been applied'::text
                END AS "gwExemption46"
           FROM (((((public.hydro_object hdo_rbd2
             LEFT JOIN public.objectives_exemption_type ON ((1 = 1)))
             LEFT JOIN public.gwb_chemical_exemption gwce ON ((objectives_exemption_type.obex_id = gwce.obex_id)))
             LEFT JOIN public.water_body ON ((water_body.wbd_id = gwce.gwb_id)))
             LEFT JOIN public.river_basin_disrict rbd ON ((rbd.rbd_id = water_body.rbd_id)))
             LEFT JOIN public.hydro_object hdo_rbd ON ((rbd.rbd_id = hdo_rbd.hdo_id)))
          WHERE ((hdo_rbd2.wkrv_id = 13) AND ((hdo_rbd2.hydro_object_type)::text = 'RiverBasinDistrict'::text) AND ((hdo_rbd2.inspire_id_local_id)::text ~~ 'NL%'::text) AND (substr(objectives_exemption_type.description, 8, 4) = '4(6)'::text))
          ORDER BY ("left"((hdo_rbd2.inspire_id_local_id)::text, 4)), gwce.obex_id
        ), e46_2 AS (
         SELECT DISTINCT ON (("left"((hdo_rbd2.inspire_id_local_id)::text, 4)), gwce.obex_id) (hdo_rbd2.hdo_id)::text AS "gWExemptionsID",
                CASE
                    WHEN (gwce.obex_id = ANY (ARRAY[4, 5, 6])) THEN 'Yes (accidents)'::text
                    ELSE 'Article 4(6) has not been applied'::text
                END AS "gwExemption46"
           FROM (((((public.hydro_object hdo_rbd2
             LEFT JOIN public.objectives_exemption_type ON ((1 = 1)))
             LEFT JOIN public.gwb_chemical_exemption gwce ON ((objectives_exemption_type.obex_id = gwce.obex_id)))
             LEFT JOIN public.water_body ON ((water_body.wbd_id = gwce.gwb_id)))
             LEFT JOIN public.river_basin_disrict rbd ON ((rbd.rbd_id = water_body.rbd_id)))
             LEFT JOIN public.hydro_object hdo_rbd ON ((rbd.rbd_id = hdo_rbd.hdo_id)))
          WHERE ((hdo_rbd2.wkrv_id = 13) AND ((hdo_rbd2.hydro_object_type)::text = 'RiverBasinDistrict'::text) AND ((hdo_rbd2.inspire_id_local_id)::text ~~ 'NL%'::text) AND (substr(objectives_exemption_type.description, 8, 4) = '4(6)'::text))
          ORDER BY ("left"((hdo_rbd2.inspire_id_local_id)::text, 4)), gwce.obex_id
        ), e46_3 AS (
         SELECT DISTINCT ON (("left"((hdo_rbd2.inspire_id_local_id)::text, 4)), gwce.obex_id) (hdo_rbd2.hdo_id)::text AS "gWExemptionsID",
                CASE
                    WHEN (gwce.obex_id = ANY (ARRAY[4, 5, 6])) THEN 'Yes (extreme floods)'::text
                    ELSE 'Article 4(6) has not been applied'::text
                END AS "gwExemption46"
           FROM (((((public.hydro_object hdo_rbd2
             LEFT JOIN public.objectives_exemption_type ON ((1 = 1)))
             LEFT JOIN public.gwb_chemical_exemption gwce ON ((objectives_exemption_type.obex_id = gwce.obex_id)))
             LEFT JOIN public.water_body ON ((water_body.wbd_id = gwce.gwb_id)))
             LEFT JOIN public.river_basin_disrict rbd ON ((rbd.rbd_id = water_body.rbd_id)))
             LEFT JOIN public.hydro_object hdo_rbd ON ((rbd.rbd_id = hdo_rbd.hdo_id)))
          WHERE ((hdo_rbd2.wkrv_id = 13) AND ((hdo_rbd2.hydro_object_type)::text = 'RiverBasinDistrict'::text) AND ((hdo_rbd2.inspire_id_local_id)::text ~~ 'NL%'::text) AND (substr(objectives_exemption_type.description, 8, 4) = '4(6)'::text))
          ORDER BY ("left"((hdo_rbd2.inspire_id_local_id)::text, 4)), gwce.obex_id
        ), e46 AS (
         SELECT e46_1."gWExemptionsID",
            e46_1."gwExemption46"
           FROM e46_1
        UNION ALL
         SELECT e46_2."gWExemptionsID",
            e46_2."gwExemption46"
           FROM e46_2
        UNION ALL
         SELECT e46_3."gWExemptionsID",
            e46_3."gwExemption46"
           FROM e46_3
        )
 SELECT DISTINCT ON (e46."gWExemptionsID", e46."gwExemption46") e46."gWExemptionsID",
    e46."gwExemption46"
   FROM e46
  ORDER BY e46."gWExemptionsID", e46."gwExemption46";


--
-- Name: vw_gwexemptions_gwexemption47; Type: VIEW; Schema: wfd_reporting; Owner: -
--

CREATE VIEW vw_gwexemptions_gwexemption47 AS
 SELECT DISTINCT ON (("left"((hdo_rbd2.inspire_id_local_id)::text, 4)), (substr(objectives_exemption_type.description, 8, 4)), gwce.obex_id) ((hdo_rbd2.hdo_id)::text || substr(objectives_exemption_type.description, 10, 1)) AS "gWExemptionsID",
        CASE
            WHEN (gwce.obex_id = ANY (ARRAY[7, 8])) THEN 'Other'::text
            ELSE 'Article 4(7) has not been applied'::text
        END AS "gwExemption47"
   FROM (((((public.hydro_object hdo_rbd2
     LEFT JOIN public.objectives_exemption_type ON ((1 = 1)))
     LEFT JOIN public.gwb_chemical_exemption gwce ON ((objectives_exemption_type.obex_id = gwce.obex_id)))
     LEFT JOIN public.water_body ON ((water_body.wbd_id = gwce.gwb_id)))
     LEFT JOIN public.river_basin_disrict rbd ON ((rbd.rbd_id = water_body.rbd_id)))
     LEFT JOIN public.hydro_object hdo_rbd ON ((rbd.rbd_id = hdo_rbd.hdo_id)))
  WHERE ((hdo_rbd2.wkrv_id = 13) AND ((hdo_rbd2.hydro_object_type)::text = 'RiverBasinDistrict'::text) AND ((hdo_rbd2.inspire_id_local_id)::text ~~ 'NL%'::text) AND (substr(objectives_exemption_type.description, 8, 4) = '4(7)'::text))
  ORDER BY ("left"((hdo_rbd2.inspire_id_local_id)::text, 4)), (substr(objectives_exemption_type.description, 8, 4)), gwce.obex_id;


--
-- Name: vw_gwpollutant; Type: VIEW; Schema: wfd_reporting; Owner: -
--

CREATE VIEW vw_gwpollutant AS
 WITH gwb_oordeel_ruw AS (
         SELECT DISTINCT ON (hdo_gwb.hdo_id, gw_chemical_status.opt_id) hdo_gwb.hdo_id AS gwb_id,
            gwb_yearly_status.year_of_status AS jaar,
            gw_chemical_status.opt_id,
            classification_type.description AS oordeel,
            waarde_bepalings_methode_type.code AS wbpm,
            wfd_qe_gwtype.is_backgroundlevelsubstance AS bglevel,
            gwb_yearly_status.gys_id
           FROM (((((public.gwb_yearly_status
             LEFT JOIN public.hydro_object hdo_gwb ON ((hdo_gwb.hdo_id = gwb_yearly_status.gwb_id)))
             JOIN public.gw_chemical_status ON ((gw_chemical_status.gys_id = gwb_yearly_status.gys_id)))
             LEFT JOIN public.classification_type ON ((gw_chemical_status.clst_id = classification_type.cls_id)))
             LEFT JOIN public.waarde_bepalings_methode_type ON ((waarde_bepalings_methode_type.wbpm_id = gw_chemical_status.wbpm_id)))
             LEFT JOIN public.wfd_qe_gwtype ON ((gw_chemical_status.opt_id = wfd_qe_gwtype.opt_id)))
          WHERE ((hdo_gwb.wkrv_id = 13) AND (gwb_yearly_status.year_of_status = ANY (ARRAY[2014, 2015])) AND (gw_chemical_status.opt_id < 4000))
          ORDER BY hdo_gwb.hdo_id, gw_chemical_status.opt_id, waarde_bepalings_methode_type.code DESC
        ), gwb_oordeel AS (
         SELECT DISTINCT ON (gwb_oordeel_ruw.gwb_id, gwb_oordeel_ruw.opt_id) gwb_oordeel_ruw.gwb_id,
            gwb_oordeel_ruw.jaar,
            gwb_oordeel_ruw.opt_id,
            gwb_oordeel_ruw.oordeel,
            gwb_oordeel_ruw.wbpm,
            gwb_oordeel_ruw.bglevel,
            observation.numeric_value
           FROM ((gwb_oordeel_ruw
             LEFT JOIN public.gw_testing_conclusion ON ((gwb_oordeel_ruw.gys_id = gw_testing_conclusion.gys_id)))
             LEFT JOIN public.observation ON (((gw_testing_conclusion.gtcc_id = observation.obs_id) AND (gwb_oordeel_ruw.opt_id = observation.observed_property_type))))
          WHERE (((gwb_oordeel_ruw.oordeel)::text = 'Ontoereikend'::text) OR (observation.numeric_value < (100)::double precision) OR (gwb_oordeel_ruw.bglevel = true))
          ORDER BY gwb_oordeel_ruw.gwb_id, gwb_oordeel_ruw.opt_id, observation.numeric_value
        ), gwb_trend AS (
         SELECT hdo_gwb.hdo_id AS gwb_id,
            gwb_yearly_status.year_of_status AS jaar,
            pollutant_trend.opt_id,
            pollutant_trend.depth_m,
            classification_type.description AS oordeel
           FROM (((public.gwb_yearly_status
             LEFT JOIN public.hydro_object hdo_gwb ON ((hdo_gwb.hdo_id = gwb_yearly_status.gwb_id)))
             JOIN public.pollutant_trend ON ((pollutant_trend.gwys_id = gwb_yearly_status.gys_id)))
             LEFT JOIN public.classification_type ON ((pollutant_trend.cls_id = classification_type.cls_id)))
          WHERE ((hdo_gwb.wkrv_id = 13) AND (gwb_yearly_status.year_of_status = ANY (ARRAY[2014, 2015])) AND (pollutant_trend.opt_id < 4000) AND ((classification_type.description)::text <> ALL (ARRAY[('Niet stijgend'::character varying)::text, ('Niet bepaald'::character varying)::text])))
        ), eu_stoffenlijst AS (
         SELECT chemische_stof_type.chs_id,
            chemische_stof_type.cas_nr,
            chemische_stof_type.naam,
            chemische_stof_type.code,
            chemische_stof_type.d_begin,
            chemische_stof_type.d_eind,
            chemische_stof_type.last_changed_date,
            chemische_stof_type.d_status,
            chemische_stof_type.id,
            eu_stoffenlijst_1.domeinnaam,
            eu_stoffenlijst_1.value,
            eu_stoffenlijst_1.grootheidcode,
            eu_stoffenlijst_1.parametercode,
            eu_stoffenlijst_1."swFailingRBSPOther"
           FROM public.chemische_stof_type,
            wfd_reporting.eu_stoffenlijst eu_stoffenlijst_1
          WHERE (((eu_stoffenlijst_1.parametercode)::text = (chemische_stof_type.code)::text) AND (((eu_stoffenlijst_1.domeinnaam)::text = 'PS_Enum'::text) OR ((eu_stoffenlijst_1.domeinnaam)::text = 'AdditionalPollutant_Enum'::text) OR ((eu_stoffenlijst_1.domeinnaam)::text = 'RBSP_Enum'::text)))
        )
 SELECT hydro_object.hdo_id AS db_id,
    ((hydro_object.hdo_id)::text || (gwb_oordeel.opt_id)::text) AS "gWPollutantID",
    hydro_object.inspire_id_local_id AS "euGroundWaterBodyCode",
        CASE
            WHEN (eu_stoffenlijst.value IS NULL) THEN grh.code
            ELSE eu_stoffenlijst.value
        END AS "gwPollutantCode",
        CASE
            WHEN ((gwb_oordeel.oordeel)::text = 'Ontoereikend'::text) THEN 'Yes'::text
            ELSE 'No'::text
        END AS "gwPollutantCausingRisk",
        CASE
            WHEN ((gwb_oordeel.oordeel)::text = 'Ontoereikend'::text) THEN 'Yes'::text
            ELSE 'No'::text
        END AS "gwPollutantCausingFailure",
        CASE
            WHEN ((gwb_trend.oordeel)::text = 'Stijgend'::text) THEN 'Yes'::text
            ELSE 'No'::text
        END AS "gwPollutantUpwardTrend",
        CASE
            WHEN ((gwb_trend.oordeel)::text = 'Omgebogen'::text) THEN 'Yes'::text
            ELSE 'No'::text
        END AS "gwPollutantTrendReversal",
        CASE
            WHEN (((gwb_oordeel.oordeel)::text = 'Goed'::text) AND (gwb_oordeel.numeric_value < (100)::double precision)) THEN 'Yes'::text
            ELSE 'No'::text
        END AS "gwPollutantsExceedancesNotCounted",
        CASE
            WHEN ((gwb_oordeel.bglevel = true) AND (bglevel.concentration_value IS NOT NULL)) THEN 'Yes'::text
            ELSE 'No'::text
        END AS "gwPollutantBackgroundLevelSet",
        CASE
            WHEN ((gwb_oordeel.bglevel = true) AND (bglevel.concentration_value IS NOT NULL)) THEN bglevel.concentration_value
            ELSE NULL::double precision
        END AS "gwPollutantBackgroundLevelValue",
        CASE
            WHEN ((gwb_oordeel.bglevel = true) AND (bglevel.concentration_value IS NOT NULL)) THEN
            CASE eenheid_type.code
                WHEN 'mg/l'::text THEN
                CASE
                    WHEN ((hoedanigheid_type.code)::text = 'Pnf'::text) THEN 'mg{P}/L'::text
                    WHEN ((hoedanigheid_type.code)::text = 'Nnf'::text) THEN 'mg{N}/L'::text
                    ELSE 'mg/L'::text
                END
                WHEN 'ug/l'::text THEN 'ug/L'::text
                ELSE NULL::text
            END
            ELSE NULL::text
        END AS "gwPollutantBackgroundLevelUnit"
   FROM (((((((((((public.hydro_object
     LEFT JOIN gwb_oordeel ON ((gwb_oordeel.gwb_id = hydro_object.hdo_id)))
     LEFT JOIN gwb_trend ON (((gwb_trend.gwb_id = hydro_object.hdo_id) AND (gwb_trend.opt_id = gwb_oordeel.opt_id))))
     LEFT JOIN public.observed_property_type ON ((observed_property_type.opt_id = gwb_oordeel.opt_id)))
     LEFT JOIN public.substance_group_element sge ON ((sge.ssge_id = observed_property_type.substance_group_id)))
     LEFT JOIN public.chemische_stof_type chs ON ((chs.chs_id = sge.chs_id)))
     LEFT JOIN public.grootheid_type grh ON ((grh.grh_id = observed_property_type.quantity_id)))
     LEFT JOIN public.natural_background_levels bglevel ON (((bglevel.gwb_id = hydro_object.hdo_id) AND (gwb_oordeel.opt_id = bglevel.opt_id))))
     LEFT JOIN public.eenheid_type ON ((bglevel.concentration_uom_id = eenheid_type.eenh_id)))
     LEFT JOIN public.observed_property_type opt ON ((opt.opt_id = bglevel.opt_id)))
     LEFT JOIN public.hoedanigheid_type ON ((opt.hoedanigheid_id = hoedanigheid_type.hdh_id)))
     JOIN eu_stoffenlijst ON (((chs.code)::text = (eu_stoffenlijst.parametercode)::text)))
  WHERE (((hydro_object.hydro_object_type)::text = 'GroundWaterBody'::text) AND (hydro_object.wkrv_id = 13));


--
-- Name: vw_gwpollutant2; Type: VIEW; Schema: wfd_reporting; Owner: -
--

CREATE VIEW vw_gwpollutant2 AS
 WITH gwb_oordeel AS (
         SELECT DISTINCT ON (hdo_gwb.hdo_id, gw_chemical_status.opt_id) hdo_gwb.hdo_id AS gwb_id,
            gwb_yearly_status.year_of_status AS jaar,
            gw_chemical_status.opt_id,
            classification_type.description AS oordeel,
            waarde_bepalings_methode_type.code AS wbpm,
            wfd_qe_gwtype.is_backgroundlevelsubstance AS bglevel
           FROM (((((public.gwb_yearly_status
             LEFT JOIN public.hydro_object hdo_gwb ON ((hdo_gwb.hdo_id = gwb_yearly_status.gwb_id)))
             JOIN public.gw_chemical_status ON ((gw_chemical_status.gys_id = gwb_yearly_status.gys_id)))
             LEFT JOIN public.classification_type ON ((gw_chemical_status.clst_id = classification_type.cls_id)))
             LEFT JOIN public.waarde_bepalings_methode_type ON ((waarde_bepalings_methode_type.wbpm_id = gw_chemical_status.wbpm_id)))
             LEFT JOIN public.wfd_qe_gwtype ON ((gw_chemical_status.opt_id = wfd_qe_gwtype.opt_id)))
          WHERE ((hdo_gwb.wkrv_id = 13) AND (gwb_yearly_status.year_of_status = ANY (ARRAY[2014, 2015])) AND (gw_chemical_status.opt_id < 4000) AND (((classification_type.description)::text = 'Ontoereikend'::text) OR (wfd_qe_gwtype.is_backgroundlevelsubstance = true)))
          ORDER BY hdo_gwb.hdo_id, gw_chemical_status.opt_id, waarde_bepalings_methode_type.code DESC
        ), gwb_trend AS (
         SELECT hdo_gwb.hdo_id AS gwb_id,
            gwb_yearly_status.year_of_status AS jaar,
            pollutant_trend.opt_id,
            pollutant_trend.depth_m,
            classification_type.description AS oordeel
           FROM (((public.gwb_yearly_status
             LEFT JOIN public.hydro_object hdo_gwb ON ((hdo_gwb.hdo_id = gwb_yearly_status.gwb_id)))
             JOIN public.pollutant_trend ON ((pollutant_trend.gwys_id = gwb_yearly_status.gys_id)))
             LEFT JOIN public.classification_type ON ((pollutant_trend.cls_id = classification_type.cls_id)))
          WHERE ((hdo_gwb.wkrv_id = 13) AND (gwb_yearly_status.year_of_status = ANY (ARRAY[2014, 2015])) AND (pollutant_trend.opt_id < 4000) AND ((classification_type.description)::text <> ALL (ARRAY[('Niet stijgend'::character varying)::text, ('Niet bepaald'::character varying)::text])))
        )
 SELECT hydro_object.hdo_id AS db_id,
    ((hydro_object.hdo_id)::text || (gwb_oordeel.opt_id)::text) AS "gWPollutantID",
    hydro_object.inspire_id_local_id AS "euGroundWaterBodyCode",
        CASE
            WHEN (chs.code IS NULL) THEN grh.code
            ELSE chs.code
        END AS "gwPollutantCode",
        CASE
            WHEN ((gwb_oordeel.oordeel)::text = 'Ontoereikend'::text) THEN 'Yes'::text
            ELSE 'No'::text
        END AS "gwPollutantCausingRisk",
        CASE
            WHEN ((gwb_oordeel.oordeel)::text = 'Ontoereikend'::text) THEN 'Yes'::text
            ELSE 'No'::text
        END AS "gwPollutantCausingFailure",
        CASE
            WHEN ((gwb_trend.oordeel)::text = 'Stijgend'::text) THEN 'Yes'::text
            ELSE 'No'::text
        END AS "gwPollutantUpwardTrend",
        CASE
            WHEN ((gwb_trend.oordeel)::text = 'Omgebogen'::text) THEN 'Yes'::text
            ELSE 'No'::text
        END AS "gwPollutantTrendReversal",
    'No'::text AS "gwPollutantsExceedancesNotCounted",
        CASE
            WHEN ((gwb_oordeel.bglevel = true) AND (bglevel.concentration_value IS NOT NULL)) THEN 'Yes'::text
            ELSE 'No'::text
        END AS "gwPollutantBackgroundLevelSet",
        CASE
            WHEN ((gwb_oordeel.bglevel = true) AND (bglevel.concentration_value IS NOT NULL)) THEN bglevel.concentration_value
            ELSE NULL::double precision
        END AS "gwPollutantBackgroundLevelValue",
        CASE
            WHEN ((gwb_oordeel.bglevel = true) AND (bglevel.concentration_value IS NOT NULL)) THEN
            CASE eenheid_type.code
                WHEN 'mg/l'::text THEN
                CASE
                    WHEN ((hoedanigheid_type.code)::text = 'Pnf'::text) THEN 'mg{P}/L'::text
                    WHEN ((hoedanigheid_type.code)::text = 'Nnf'::text) THEN 'mg{N}/L'::text
                    ELSE 'mg/L'::text
                END
                WHEN 'ug/l'::text THEN 'ug/L'::text
                ELSE NULL::text
            END
            ELSE NULL::text
        END AS "gwPollutantBackgroundLevelUnit"
   FROM ((((((((((public.hydro_object
     LEFT JOIN gwb_oordeel ON ((gwb_oordeel.gwb_id = hydro_object.hdo_id)))
     LEFT JOIN gwb_trend ON (((gwb_trend.gwb_id = hydro_object.hdo_id) AND (gwb_trend.opt_id = gwb_oordeel.opt_id))))
     LEFT JOIN public.observed_property_type ON ((observed_property_type.opt_id = gwb_oordeel.opt_id)))
     LEFT JOIN public.substance_group_element sge ON ((sge.ssge_id = observed_property_type.substance_group_id)))
     LEFT JOIN public.chemische_stof_type chs ON ((chs.chs_id = sge.chs_id)))
     LEFT JOIN public.grootheid_type grh ON ((grh.grh_id = observed_property_type.quantity_id)))
     LEFT JOIN public.natural_background_levels bglevel ON (((bglevel.gwb_id = hydro_object.hdo_id) AND (gwb_oordeel.opt_id = bglevel.opt_id))))
     LEFT JOIN public.eenheid_type ON ((bglevel.concentration_uom_id = eenheid_type.eenh_id)))
     LEFT JOIN public.observed_property_type opt ON ((opt.opt_id = bglevel.opt_id)))
     LEFT JOIN public.hoedanigheid_type ON ((opt.hoedanigheid_id = hoedanigheid_type.hdh_id)))
  WHERE (((hydro_object.hydro_object_type)::text = 'GroundWaterBody'::text) AND (hydro_object.wkrv_id = 13));


--
-- Name: vw_ktm; Type: VIEW; Schema: wfd_reporting; Owner: -
--

CREATE VIEW vw_ktm AS
 SELECT DISTINCT ON (rbd.inspire_id_local_id, ktm_enum.eu_xsd) (((rbd.inspire_id_local_id)::text || '-'::text) || "substring"((ktm_enum.eu_xsd)::text, 1, ("position"((ktm_enum.eu_xsd)::text, ' - '::text) - 1))) AS "kTMID",
    rbd.inspire_id_local_id AS "euRBDCode",
    ktm_enum.eu_xsd AS "keyTypeMeasure",
        CASE
            WHEN ("substring"((ktm_enum.eu_xsd)::text, 1, ("position"((ktm_enum.eu_xsd)::text, ' - '::text) - 1)) = 'KTM99'::text) THEN 'No additional information available'::text
            ELSE NULL::text
        END AS "keyTypeMeasureOther"
   FROM ((((public.sw_supp_measure_eu_type
     JOIN public.supp_add_measure_type smnl ON ((smnl.smeu_id = sw_supp_measure_eu_type.smeu_id)))
     FULL JOIN ktm_enum ON ((ktm_enum.smeu_id = smnl.smeu_id)))
     LEFT JOIN public.river_basin_management_plan rbmp ON (((smnl.rbmp_id = rbmp.rbmp_id) AND (rbmp.wkrv_id = 13))))
     JOIN public.hydro_object rbd ON ((rbd.hdo_id = rbmp.rbd_id)))
  ORDER BY rbd.inspire_id_local_id, ktm_enum.eu_xsd;


--
-- Name: vw_linksurfacewaterbodycode; Type: VIEW; Schema: wfd_reporting; Owner: -
--

CREATE VIEW vw_linksurfacewaterbodycode AS
 SELECT gwb.hdo_id,
    gwb.inspire_id_local_id AS "euGroundWaterBodyCode",
    swb.inspire_id_local_id AS "linkSurfaceWaterBodyCode",
    "left"((srbd.inspire_id_local_id)::text, 4) AS rbd
   FROM ((((((public.hydro_object gwb
     JOIN public.water_body gwbd ON ((gwbd.wbd_id = gwb.hdo_id)))
     JOIN public.hydro_object grbd ON (((grbd.hdo_id = gwbd.rbd_id) AND (grbd.wkrv_id = 13))))
     JOIN public.relation_gwb_swb ON ((relation_gwb_swb.gwb_id = gwb.hdo_id)))
     JOIN public.hydro_object swb ON (((relation_gwb_swb.swb_id = swb.hdo_id) AND (swb.wkrv_id = 13))))
     JOIN public.water_body swbd ON ((swbd.wbd_id = swb.hdo_id)))
     JOIN public.hydro_object srbd ON (((srbd.hdo_id = swbd.rbd_id) AND (srbd.wkrv_id = 13) AND ((srbd.hydro_object_type)::text = 'RiverBasinDistrict'::text))))
  WHERE ((gwb.wkrv_id = 13) AND ("left"((srbd.inspire_id_local_id)::text, 4) = "left"((grbd.inspire_id_local_id)::text, 4)));


--
-- Name: vw_measure; Type: VIEW; Schema: wfd_reporting; Owner: -
--

CREATE VIEW vw_measure AS
 SELECT DISTINCT ON (rbd.inspire_id_local_id, smnl.smeu_id, ktm_enum.eu_xsd) ((rbd.inspire_id_local_id)::text || smnl.smeu_id) AS "measureID",
    (((rbd.inspire_id_local_id)::text || '-'::text) || "substring"((ktm_enum.eu_xsd)::text, 1, ("position"((ktm_enum.eu_xsd)::text, ' - '::text) - 1))) AS "kTMID",
    sw_supp_measure_eu_type.code AS "measureCode",
    sw_supp_measure_eu_type.name AS "measureName",
        CASE sw_supp_measure_eu_type.tablkop_sgbp
            WHEN 'aanpak diffuse bronnen'::text THEN 'Basic'::text
            WHEN 'regulering waterbeweging en hydromorfologie'::text THEN 'Basic'::text
            WHEN 'aanvullende maatregelen'::text THEN 'Supplementary'::text
            WHEN 'aanpak puntbronnen'::text THEN 'Basic'::text
            WHEN 'uitvoeren onderzoek'::text THEN 'Supplementary'::text
            WHEN 'wateronttrekking grond- en oppervlaktewater'::text THEN 'Basic'::text
            ELSE 'Basic'::text
        END AS "measureType",
    'No'::text AS "msfdRelevance"
   FROM ((((public.sw_supp_measure_eu_type
     JOIN public.supp_add_measure_type smnl ON ((smnl.smeu_id = sw_supp_measure_eu_type.smeu_id)))
     FULL JOIN ktm_enum ON ((ktm_enum.smeu_id = smnl.smeu_id)))
     LEFT JOIN public.river_basin_management_plan rbmp ON (((smnl.rbmp_id = rbmp.rbmp_id) AND (rbmp.wkrv_id = 13))))
     JOIN public.hydro_object rbd ON ((rbd.hdo_id = rbmp.rbd_id)))
  ORDER BY rbd.inspire_id_local_id, smnl.smeu_id, ktm_enum.eu_xsd;


--
-- Name: vw_measure_basicmeasuretype; Type: VIEW; Schema: wfd_reporting; Owner: -
--

CREATE VIEW vw_measure_basicmeasuretype AS
 WITH measure AS (
         SELECT DISTINCT ON (rbd.inspire_id_local_id, smnl.smeu_id, ktm_enum.eu_xsd) smnl.smeu_id,
            ((rbd.inspire_id_local_id)::text || smnl.smeu_id) AS "measureID",
            (((rbd.inspire_id_local_id)::text || '-'::text) || "substring"((ktm_enum.eu_xsd)::text, 1, ("position"((ktm_enum.eu_xsd)::text, ' - '::text) - 1))) AS "kTMID",
            sw_supp_measure_eu_type.code AS "measureCode",
            sw_supp_measure_eu_type.name AS "measureName",
                CASE sw_supp_measure_eu_type.tablkop_sgbp
                    WHEN 'aanpak diffuse bronnen'::text THEN 'Basic'::text
                    WHEN 'regulering waterbeweging en hydromorfologie'::text THEN 'Basic'::text
                    WHEN 'aanvullende maatregelen'::text THEN 'Supplementary'::text
                    WHEN 'aanpak puntbronnen'::text THEN 'Basic'::text
                    WHEN 'uitvoeren onderzoek'::text THEN 'Supplementary'::text
                    WHEN 'wateronttrekking grond- en oppervlaktewater'::text THEN 'Basic'::text
                    ELSE 'Basic'::text
                END AS "measureType",
            'No' AS "msfdRelevance"
           FROM ((((public.sw_supp_measure_eu_type
             JOIN public.supp_add_measure_type smnl ON ((smnl.smeu_id = sw_supp_measure_eu_type.smeu_id)))
             FULL JOIN ktm_enum ON ((ktm_enum.smeu_id = smnl.smeu_id)))
             LEFT JOIN public.river_basin_management_plan rbmp ON (((smnl.rbmp_id = rbmp.rbmp_id) AND (rbmp.wkrv_id = 13))))
             JOIN public.hydro_object rbd ON ((rbd.hdo_id = rbmp.rbd_id)))
          ORDER BY rbd.inspire_id_local_id, smnl.smeu_id, ktm_enum.eu_xsd
        ), basics AS (
         SELECT sw_supp_measure_eu_type.smeu_id,
                CASE sw_supp_measure_eu_type.tablkop_sgbp
                    WHEN 'aanpak diffuse bronnen'::text THEN 'Pollutants diffuse'::text
                    WHEN 'regulering waterbeweging en hydromorfologie'::text THEN 'Hydromorphology'::text
                    WHEN 'aanpak puntbronnen'::text THEN 'Point source discharges'::text
                    WHEN 'wateronttrekking grond- en oppervlaktewater'::text THEN 'Controls water abstraction'::text
                    ELSE NULL::text
                END AS basic
           FROM public.sw_supp_measure_eu_type
        UNION
         SELECT sw_supp_measure_eu_type.smeu_id,
                CASE sw_supp_measure_eu_type.tablkop_sgbp
                    WHEN 'aanpak puntbronnen'::text THEN 'Pollutants direct groundwater'::text
                    WHEN 'wateronttrekking grond- en oppervlaktewater'::text THEN 'Recharge augmentation groundwaters'::text
                    ELSE NULL::text
                END AS basic
           FROM public.sw_supp_measure_eu_type
        UNION
         SELECT sw_supp_measure_eu_type.smeu_id,
                CASE sw_supp_measure_eu_type.tablkop_sgbp
                    WHEN 'wateronttrekking grond- en oppervlaktewater'::text THEN 'Protection water abstraction'::text
                    ELSE NULL::text
                END AS basic
           FROM public.sw_supp_measure_eu_type
        ), basics2 AS (
         SELECT DISTINCT ON (basics.smeu_id, basics.basic) basics.smeu_id,
            basics.basic
           FROM basics
          WHERE (basics.basic IS NOT NULL)
          ORDER BY basics.smeu_id, basics.basic
        )
 SELECT DISTINCT ON (measure."measureID", basics2.basic) measure."measureID",
    basics2.basic AS "basicMeasureType"
   FROM (basics2
     JOIN measure ON (((measure.smeu_id = basics2.smeu_id) AND (measure."measureID" IS NOT NULL))))
  WHERE (basics2.basic IS NOT NULL)
  ORDER BY measure."measureID", basics2.basic;


--
-- Name: vw_monitoringpurpose; Type: VIEW; Schema: wfd_reporting; Owner: -
--

CREATE VIEW vw_monitoringpurpose AS
 SELECT DISTINCT ON (mpn.mpnident) 'CHE - Chemical status'::text AS "monitoringPurpose",
        CASE
            WHEN ((mpn.montype)::text = 'ow'::text) THEN ("left"((mpn.sgb)::text, 4) || '_MONPROG_OW'::text)
            ELSE ("left"((mpn.sgb)::text, 4) || '_MONPROG_GW'::text)
        END AS "euProgrammeCode",
        CASE
            WHEN ("substring"((mpn.mpnident)::text, 1, 2) <> 'NL'::text) THEN ('NL_'::text || (mpn.mpnident)::text)
            ELSE (mpn.mpnident)::text
        END AS "euMonitoringSiteCode"
   FROM eu_state_of_environment.monprog_2015 mpn
  WHERE ((mpn.purpose)::text = 'chemie'::text)
UNION ALL
 SELECT DISTINCT ON (mpn.mpnident) 'DRI - Groundwater abstraction site for human consumption'::text AS "monitoringPurpose",
        CASE
            WHEN ((mpn.montype)::text = 'ow'::text) THEN ("left"((mpn.sgb)::text, 4) || '_MONPROG_OW'::text)
            ELSE ("left"((mpn.sgb)::text, 4) || '_MONPROG_GW'::text)
        END AS "euProgrammeCode",
        CASE
            WHEN ("substring"((mpn.mpnident)::text, 1, 2) <> 'NL'::text) THEN ('NL_'::text || (mpn.mpnident)::text)
            ELSE (mpn.mpnident)::text
        END AS "euMonitoringSiteCode"
   FROM eu_state_of_environment.monprog_2015 mpn
  WHERE ((mpn.purpose)::text = 'drinkwater'::text)
UNION ALL
 SELECT DISTINCT ON (mpn.mpnident) 'ECO - Ecological status'::text AS "monitoringPurpose",
        CASE
            WHEN ((mpn.montype)::text = 'ow'::text) THEN ("left"((mpn.sgb)::text, 4) || '_MONPROG_OW'::text)
            ELSE ("left"((mpn.sgb)::text, 4) || '_MONPROG_GW'::text)
        END AS "euProgrammeCode",
        CASE
            WHEN ("substring"((mpn.mpnident)::text, 1, 2) <> 'NL'::text) THEN ('NL_'::text || (mpn.mpnident)::text)
            ELSE (mpn.mpnident)::text
        END AS "euMonitoringSiteCode"
   FROM eu_state_of_environment.monprog_2015 mpn
  WHERE ((mpn.purpose)::text = 'ecologie'::text)
UNION ALL
 SELECT DISTINCT ON (mpn.mpnident) 'OPE - Operational monitoring'::text AS "monitoringPurpose",
        CASE
            WHEN ((mpn.montype)::text = 'ow'::text) THEN ("left"((mpn.sgb)::text, 4) || '_MONPROG_OW'::text)
            ELSE ("left"((mpn.sgb)::text, 4) || '_MONPROG_GW'::text)
        END AS "euProgrammeCode",
        CASE
            WHEN ("substring"((mpn.mpnident)::text, 1, 2) <> 'NL'::text) THEN ('NL_'::text || (mpn.mpnident)::text)
            ELSE (mpn.mpnident)::text
        END AS "euMonitoringSiteCode"
   FROM eu_state_of_environment.monprog_2015 mpn
  WHERE ((mpn.monsoort)::text = 'OM'::text)
UNION ALL
 SELECT DISTINCT ON (mpn.mpnident) 'QUA - Quantitative status'::text AS "monitoringPurpose",
        CASE
            WHEN ((mpn.montype)::text = 'ow'::text) THEN ("left"((mpn.sgb)::text, 4) || '_MONPROG_OW'::text)
            ELSE ("left"((mpn.sgb)::text, 4) || '_MONPROG_GW'::text)
        END AS "euProgrammeCode",
        CASE
            WHEN ("substring"((mpn.mpnident)::text, 1, 2) <> 'NL'::text) THEN ('NL_'::text || (mpn.mpnident)::text)
            ELSE (mpn.mpnident)::text
        END AS "euMonitoringSiteCode"
   FROM eu_state_of_environment.monprog_2015 mpn
  WHERE ((mpn.purpose)::text = 'kwantiteit'::text)
UNION ALL
 SELECT DISTINCT ON (mpn.mpnident) 'SUR - Surveillance monitoring'::text AS "monitoringPurpose",
        CASE
            WHEN ((mpn.montype)::text = 'ow'::text) THEN ("left"((mpn.sgb)::text, 4) || '_MONPROG_OW'::text)
            ELSE ("left"((mpn.sgb)::text, 4) || '_MONPROG_GW'::text)
        END AS "euProgrammeCode",
        CASE
            WHEN ("substring"((mpn.mpnident)::text, 1, 2) <> 'NL'::text) THEN ('NL_'::text || (mpn.mpnident)::text)
            ELSE (mpn.mpnident)::text
        END AS "euMonitoringSiteCode"
   FROM eu_state_of_environment.monprog_2015 mpn
  WHERE ((mpn.monsoort)::text = 'TT'::text)
UNION ALL
 SELECT DISTINCT ON (mpn.mpnident) 'SOE - EIONET State of Environment monitoring'::text AS "monitoringPurpose",
        CASE
            WHEN ((mpn.montype)::text = 'ow'::text) THEN ("left"((mpn.sgb)::text, 4) || '_MONPROG_OW'::text)
            ELSE ("left"((mpn.sgb)::text, 4) || '_MONPROG_GW'::text)
        END AS "euProgrammeCode",
        CASE
            WHEN ("substring"((mpn.mpnident)::text, 1, 2) <> 'NL'::text) THEN ('NL_'::text || (mpn.mpnident)::text)
            ELSE (mpn.mpnident)::text
        END AS "euMonitoringSiteCode"
   FROM eu_state_of_environment.monprog_2015 mpn
  WHERE (("left"((mpn.mpnident)::text, 3) = ANY (ARRAY['NL8'::text, 'NL9'::text])) AND ("left"((mpn.mpnident)::text, 4) <> 'NL99'::text))
UNION ALL
 SELECT DISTINCT ON (mpn.mpnident) 'TRE - Chemical trend assessment'::text AS "monitoringPurpose",
        CASE
            WHEN ((mpn.montype)::text = 'ow'::text) THEN ("left"((mpn.sgb)::text, 4) || '_MONPROG_OW'::text)
            ELSE ("left"((mpn.sgb)::text, 4) || '_MONPROG_GW'::text)
        END AS "euProgrammeCode",
        CASE
            WHEN ("substring"((mpn.mpnident)::text, 1, 2) <> 'NL'::text) THEN ('NL_'::text || (mpn.mpnident)::text)
            ELSE (mpn.mpnident)::text
        END AS "euMonitoringSiteCode"
   FROM eu_state_of_environment.monprog_2015 mpn
  WHERE (((mpn.purpose)::text = 'chemie'::text) AND ((mpn.montype)::text = 'gw'::text))
  ORDER BY 3;


--
-- Name: vw_monitoringsite; Type: VIEW; Schema: wfd_reporting; Owner: -
--

CREATE VIEW vw_monitoringsite AS
 WITH mpn AS (
         SELECT DISTINCT ON (monprog_2015.mpnident) monprog_2015.mpnident,
            monprog_2015.ligt_in_owm,
                CASE
                    WHEN ((monprog_2015.rd_x IS NULL) OR (monprog_2015.rd_x = (0)::double precision)) THEN ((155000)::numeric)::double precision
                    ELSE monprog_2015.rd_x
                END AS rd_x,
                CASE
                    WHEN ((monprog_2015.rd_y IS NULL) OR (monprog_2015.rd_x = (0)::double precision)) THEN ((463000)::numeric)::double precision
                    ELSE monprog_2015.rd_y
                END AS rd_y,
            monprog_2015.parameter,
            monprog_2015.monfreq,
            monprog_2015.moncyclus,
            monprog_2015.monsoort,
            monprog_2015.repr_owm,
            monprog_2015.mpntype,
            monprog_2015.diepte,
            monprog_2015.montype,
            monprog_2015.sinds,
            monprog_2015.tot,
            monprog_2015.naam,
            monprog_2015.purpose,
            monprog_2015.sgb
           FROM eu_state_of_environment.monprog_2015
          ORDER BY monprog_2015.mpnident
        ), chem AS (
         SELECT DISTINCT ON (monprog_2015.mpnident) monprog_2015.mpnident
           FROM eu_state_of_environment.monprog_2015
          WHERE ((monprog_2015.purpose)::text = ANY (ARRAY[('chemie'::character varying)::text, ('drinkwater'::character varying)::text]))
          ORDER BY monprog_2015.mpnident
        ), ecol AS (
         SELECT DISTINCT ON (monprog_2015.mpnident) monprog_2015.mpnident
           FROM eu_state_of_environment.monprog_2015
          WHERE ((monprog_2015.purpose)::text = 'ecologie'::text)
          ORDER BY monprog_2015.mpnident
        ), kwant AS (
         SELECT DISTINCT ON (monprog_2015.mpnident) monprog_2015.mpnident,
            monprog_2015.monfreq,
            monprog_2015.moncyclus,
            monprog_2015.sinds,
            monprog_2015.tot
           FROM eu_state_of_environment.monprog_2015
          WHERE ((monprog_2015.purpose)::text = 'kwantiteit'::text)
          ORDER BY monprog_2015.mpnident
        )
 SELECT
        CASE
            WHEN ("substring"((mpn.mpnident)::text, 1, 2) <> 'NL'::text) THEN ('NL_'::text || (mpn.mpnident)::text)
            ELSE (mpn.mpnident)::text
        END AS "euMonitoringSiteCode",
    mpn.naam AS "euMonitoringSiteName",
    (mpn.ligt_in_owm)::text AS "euWaterBodyCode",
        CASE "left"((swt.code)::text, 1)
            WHEN 'K'::text THEN 'CW'::text
            WHEN 'O'::text THEN 'TW'::text
            WHEN 'M'::text THEN 'LW'::text
            WHEN 'R'::text THEN 'RW'::text
            ELSE 'GW'::text
        END AS "waterCategory",
        CASE
            WHEN ((mpn.montype)::text = 'ow'::text) THEN
            CASE
                WHEN (ecol.mpnident IS NOT NULL) THEN 'Yes'::text
                ELSE 'No'::text
            END
            ELSE 'Not applicable'::text
        END AS "ecologicalMonitoring",
        CASE
            WHEN (chem.mpnident IS NOT NULL) THEN 'Yes'::text
            ELSE 'No'::text
        END AS "chemicalMonitoring",
        CASE
            WHEN ((mpn.montype)::text <> 'ow'::text) THEN
            CASE
                WHEN (kwant.mpnident IS NOT NULL) THEN 'Yes'::text
                ELSE 'No'::text
            END
            ELSE 'Not applicable'::text
        END AS "quantitativeMonitoring",
    kwant.monfreq AS "quantitativeFrequency",
    kwant.moncyclus AS "quantitativeCycle",
    kwant.tot AS "quantitativeLastMonitored",
        CASE
            WHEN ((mpn.montype)::text = 'ow'::text) THEN NULL::text
            ELSE
            CASE
                WHEN ((mpn.mpntype)::text = 'bron'::text) THEN 'Spring'::text
                ELSE 'Well'::text
            END
        END AS "wellSpring",
        CASE
            WHEN ((mpn.montype)::text = 'ow'::text) THEN NULL::text
            ELSE
            CASE mpn.diepte
                WHEN 'Ondiep'::text THEN 'Upper'::text
                WHEN 'ondiep'::text THEN 'Upper'::text
                WHEN 'medium'::text THEN 'Medium'::text
                WHEN 'diep'::text THEN 'Lower'::text
                WHEN 'zeer diep'::text THEN 'Lower'::text
                ELSE 'Mixed'::text
            END
        END AS depth,
    mpn.sgb AS "euRBDCode"
   FROM ((((mpn
     LEFT JOIN (public.hydro_object hdo
     JOIN (public.surface_water_body swb
     JOIN public.sw_typology_type swt ON ((swt.styp_id = swb.sw_typology_id))) ON ((swb.swb_id = hdo.hdo_id))) ON ((((hdo.inspire_id_local_id)::text = (mpn.ligt_in_owm)::text) AND (hdo.wkrv_id = 13) AND ((hdo.hydro_object_type)::text = 'SurfaceWaterBody'::text))))
     LEFT JOIN chem ON (((chem.mpnident)::text = (mpn.mpnident)::text)))
     LEFT JOIN ecol ON (((ecol.mpnident)::text = (mpn.mpnident)::text)))
     LEFT JOIN kwant ON (((kwant.mpnident)::text = (mpn.mpnident)::text)));


--
-- Name: vw_quality_element_missing; Type: VIEW; Schema: wfd_reporting; Owner: -
--

CREATE VIEW vw_quality_element_missing AS
 SELECT missing_qe.qetype,
    hydro_object.inspire_id_local_id
   FROM missing_qe,
    public.hydro_object
  WHERE ((hydro_object.wkrv_id = 13) AND ((hydro_object.hydro_object_type)::text = 'SurfaceWaterBody'::text))
  ORDER BY hydro_object.inspire_id_local_id;


--
-- Name: vw_qualityelement; Type: VIEW; Schema: wfd_reporting; Owner: -
--

CREATE VIEW vw_qualityelement AS
 WITH oordeel_2015 AS (
         SELECT DISTINCT ON (swb.swb_id, ses.opt_id) swb.swb_id,
            ses.opt_id,
            ses.wbpm_id,
            hydro_object.inspire_id_local_id,
            ses.swes_id AS cls_id,
            swb.sw_target_typology_id
           FROM (((public.surface_water_body swb
             LEFT JOIN public.hydro_object ON ((hydro_object.hdo_id = swb.swb_id)))
             LEFT JOIN public.swb_yearly_status ON (((swb.swb_id = swb_yearly_status.swb_id) AND (swb_yearly_status.year_of_status = 2015))))
             LEFT JOIN public.sw_ecological_status ses ON (((ses.sys_id = swb_yearly_status.sys_id) AND (ses.opt_id = ANY (ARRAY[579, 3685, 4212, 3841, 3773, 619, 2948, 4507, 4515, 4521, 4482, 632])))))
          WHERE ((ses.eumg_id = 3) AND (hydro_object.wkrv_id = 13))
        UNION ALL
         SELECT DISTINCT ON (swb.swb_id, ses.opt_id) swb.swb_id,
            ses.opt_id,
            ses.wbpm_id,
            hydro_object.inspire_id_local_id,
            ses.swcs_id AS cls_id,
            swb.sw_target_typology_id
           FROM (((public.surface_water_body swb
             LEFT JOIN public.hydro_object ON ((hydro_object.hdo_id = swb.swb_id)))
             LEFT JOIN public.swb_yearly_status ON (((swb.swb_id = swb_yearly_status.swb_id) AND (swb_yearly_status.year_of_status = 2015))))
             LEFT JOIN public.sw_chemical_substance_status ses ON (((ses.sys_id = swb_yearly_status.sys_id) AND (ses.opt_id = 4519))))
          WHERE ((ses.eumg_id = 3) AND (hydro_object.wkrv_id = 13))
  ORDER BY 1, 2, 3 DESC
        ), oordeel_qe_2015 AS (
         SELECT swb.swb_id,
            wfd_qe_swtype.opt_id,
            ((swb.swb_id)::text || (wfd_qe_swtype.opt_id)::text) AS "qualityElementID",
            hydro_object.inspire_id_local_id AS "euSurfaceWaterBodyCode",
                CASE wfd_qe_swtype.opt_id
                    WHEN 579 THEN 'QE3-1-4 - Salinity conditions'::text
                    WHEN 619 THEN 'QE3-1-6-1 - Nitrogen conditions'::text
                    WHEN 2948 THEN 'QE3-1-6-1 - Nitrogen conditions'::text
                    WHEN 3685 THEN 'QE3-1-5 - Acidification status'::text
                    WHEN 4212 THEN 'QE3-1-3 - Oxygenation conditions'::text
                    WHEN 3841 THEN 'QE3-1-1 - Transparency conditions'::text
                    WHEN 3773 THEN 'QE3-1-2 - Thermal conditions'::text
                    WHEN 4519 THEN 'QE3-3 - River Basin Specific Pollutants'::text
                    WHEN 4507 THEN 'QE1-3 – Benthic invertebrates'::text
                    WHEN 4515 THEN 'QE1-2 - Other aquatic flora'::text
                    WHEN 4521 THEN 'QE1-4 - Fish'::text
                    WHEN 4482 THEN 'QE1-1 - Phytoplankton'::text
                    WHEN 632 THEN 'QE3-1-6-2 - Phosphorus Conditions'::text
                    ELSE NULL::text
                END AS "qeCode",
                CASE
                    WHEN (wfd_qe_swtype.is_applicable IS TRUE) THEN (
                    CASE
                        WHEN ((classification_type.code)::integer = ANY (ARRAY[1, 2, 3, 4, 5])) THEN
                        CASE
                            WHEN (wfd_qe_swtype.opt_id = ANY (ARRAY[579, 3685, 4212, 3841, 3773, 4519, 619, 2948, 632])) THEN
                            CASE
                                WHEN ((classification_type.code)::integer > 3) THEN ((3)::text)::character varying
                                ELSE classification_type.code
                            END
                            ELSE classification_type.code
                        END
                        ELSE 'Unknown'::character varying
                    END)::text
                    ELSE 'Not applicable'::text
                END AS "qeStatusOrPotentialValue",
                CASE
                    WHEN ((wfd_qe_swtype.is_applicable IS TRUE) AND (oordeel_2015.wbpm_id IS NOT NULL)) THEN
                    CASE
                        WHEN (oordeel_2015.wbpm_id = 1) THEN 'Monitoring'::text
                        ELSE 'Expert judgement'::text
                    END
                    ELSE NULL::text
                END AS "qeMonitoringResults",
                CASE
                    WHEN ((wfd_qe_swtype.is_applicable IS TRUE) AND (oordeel_2015.wbpm_id IS NOT NULL)) THEN
                    CASE
                        WHEN (oordeel_2015.wbpm_id = 1) THEN '2009-2014'::text
                        ELSE NULL::text
                    END
                    ELSE NULL::text
                END AS "qeMonitoringPeriod",
                CASE
                    WHEN (wfd_qe_swtype.is_applicable IS TRUE) THEN (
                    CASE
                        WHEN ((classification_type.code)::integer = ANY (ARRAY[1, 2, 3, 4, 5])) THEN
                        CASE
                            WHEN (wfd_qe_swtype.opt_id = ANY (ARRAY[579, 3685, 4212, 3841, 3773, 4519, 619, 2948, 632])) THEN
                            CASE
                                WHEN ((classification_type.code)::integer > 3) THEN ((3)::text)::character varying
                                ELSE classification_type.code
                            END
                            ELSE classification_type.code
                        END
                        ELSE '0'::character varying
                    END)::text
                    ELSE '6'::text
                END AS cls_code
           FROM ((((public.surface_water_body swb
             LEFT JOIN public.hydro_object ON ((hydro_object.hdo_id = swb.swb_id)))
             LEFT JOIN public.wfd_qe_swtype ON (((swb.sw_target_typology_id = wfd_qe_swtype.swt_id) AND (wfd_qe_swtype.opt_id <> ALL (ARRAY[4477, 4520, 4480, 4476, 4479, 5892, 5893, 5891, 4514])))))
             LEFT JOIN oordeel_2015 ON (((oordeel_2015.swb_id = swb.swb_id) AND (oordeel_2015.opt_id = wfd_qe_swtype.opt_id))))
             LEFT JOIN public.classification_type ON ((classification_type.cls_id = oordeel_2015.cls_id)))
          WHERE (hydro_object.wkrv_id = 13)
        ), qe_2015 AS (
         SELECT DISTINCT ON (oordeel_qe_2015_1."euSurfaceWaterBodyCode", oordeel_qe_2015_1."qeCode") oordeel_qe_2015_1.swb_id,
            oordeel_qe_2015_1.opt_id AS "qualityElementID",
            oordeel_qe_2015_1."euSurfaceWaterBodyCode",
            oordeel_qe_2015_1."qeCode",
            oordeel_qe_2015_1."qeStatusOrPotentialValue",
            oordeel_qe_2015_1."qeMonitoringResults",
            oordeel_qe_2015_1."qeMonitoringPeriod",
            oordeel_qe_2015_1.cls_code
           FROM oordeel_qe_2015 oordeel_qe_2015_1
          ORDER BY oordeel_qe_2015_1."euSurfaceWaterBodyCode", oordeel_qe_2015_1."qeCode", oordeel_qe_2015_1.cls_code
        ), oordeel_2009 AS (
         SELECT DISTINCT ON (swb.swb_id, ses.opt_id) swb.swb_id,
            ses.opt_id,
            ses.wbpm_id,
            hydro_object.inspire_id_local_id,
            ses.swes_id AS cls_id,
            swb.sw_target_typology_id
           FROM (((public.surface_water_body swb
             LEFT JOIN public.hydro_object ON ((hydro_object.hdo_id = swb.swb_id)))
             LEFT JOIN public.swb_yearly_status ON (((swb.swb_id = swb_yearly_status.swb_id) AND (swb_yearly_status.year_of_status = 2009))))
             LEFT JOIN public.sw_ecological_status ses ON (((ses.sys_id = swb_yearly_status.sys_id) AND (ses.opt_id = ANY (ARRAY[579, 3685, 4212, 3841, 3773, 619, 2948, 4507, 4515, 4521, 4482, 632])))))
          WHERE ((ses.eumg_id = 3) AND (hydro_object.wkrv_id = 2))
        UNION ALL
         SELECT DISTINCT ON (swb.swb_id, ses.opt_id) swb.swb_id,
            ses.opt_id,
            ses.wbpm_id,
            hydro_object.inspire_id_local_id,
            ses.swcs_id AS cls_id,
            swb.sw_target_typology_id
           FROM (((public.surface_water_body swb
             LEFT JOIN public.hydro_object ON ((hydro_object.hdo_id = swb.swb_id)))
             LEFT JOIN public.swb_yearly_status ON (((swb.swb_id = swb_yearly_status.swb_id) AND (swb_yearly_status.year_of_status = 2009))))
             LEFT JOIN public.sw_chemical_substance_status ses ON (((ses.sys_id = swb_yearly_status.sys_id) AND (ses.opt_id = 4519))))
          WHERE ((ses.eumg_id = 3) AND (hydro_object.wkrv_id = 2))
  ORDER BY 1, 2, 3 DESC
        ), oordeel_qe_2009 AS (
         SELECT swb.swb_id,
            wfd_qe_swtype.opt_id,
            ((swb.swb_id)::text || (wfd_qe_swtype.opt_id)::text) AS "qualityElementID",
            hydro_object.inspire_id_local_id AS "euSurfaceWaterBodyCode",
                CASE wfd_qe_swtype.opt_id
                    WHEN 579 THEN 'QE3-1-4 - Salinity conditions'::text
                    WHEN 619 THEN 'QE3-1-6-1 - Nitrogen conditions'::text
                    WHEN 2948 THEN 'QE3-1-6-1 - Nitrogen conditions'::text
                    WHEN 3685 THEN 'QE3-1-5 - Acidification status'::text
                    WHEN 4212 THEN 'QE3-1-3 - Oxygenation conditions'::text
                    WHEN 3841 THEN 'QE3-1-1 - Transparency conditions'::text
                    WHEN 3773 THEN 'QE3-1-2 - Thermal conditions'::text
                    WHEN 4519 THEN 'QE3-3 - River Basin Specific Pollutants'::text
                    WHEN 4507 THEN 'QE1-3 – Benthic invertebrates'::text
                    WHEN 4515 THEN 'QE1-2 - Other aquatic flora'::text
                    WHEN 4521 THEN 'QE1-4 - Fish'::text
                    WHEN 4482 THEN 'QE1-1 - Phytoplankton'::text
                    WHEN 632 THEN 'QE3-1-6-2 - Phosphorus Conditions'::text
                    ELSE NULL::text
                END AS "qeCode",
                CASE
                    WHEN (wfd_qe_swtype.is_applicable IS TRUE) THEN (
                    CASE
                        WHEN ((classification_type.code)::integer = ANY (ARRAY[1, 2, 3, 4, 5])) THEN
                        CASE
                            WHEN (wfd_qe_swtype.opt_id = ANY (ARRAY[579, 3685, 4212, 3841, 3773, 4519, 619, 2948, 632])) THEN
                            CASE
                                WHEN ((classification_type.code)::integer > 3) THEN ((3)::text)::character varying
                                ELSE classification_type.code
                            END
                            ELSE classification_type.code
                        END
                        ELSE 'Unknown'::character varying
                    END)::text
                    ELSE 'Not applicable'::text
                END AS "qeStatusOrPotentialValue",
                CASE
                    WHEN (wfd_qe_swtype.is_applicable IS TRUE) THEN
                    CASE
                        WHEN (oordeel_2009.wbpm_id = 1) THEN 'Monitoring'::text
                        ELSE 'Expert judgement'::text
                    END
                    ELSE NULL::text
                END AS "qeMonitoringResults",
                CASE
                    WHEN (wfd_qe_swtype.is_applicable IS TRUE) THEN
                    CASE
                        WHEN (oordeel_2009.wbpm_id = 1) THEN '2009-2014'::text
                        ELSE NULL::text
                    END
                    ELSE NULL::text
                END AS "qeMonitoringPeriod",
                CASE
                    WHEN (wfd_qe_swtype.is_applicable IS TRUE) THEN (
                    CASE
                        WHEN ((classification_type.code)::integer = ANY (ARRAY[1, 2, 3, 4, 5])) THEN
                        CASE
                            WHEN (wfd_qe_swtype.opt_id = ANY (ARRAY[579, 3685, 4212, 3841, 3773, 4519, 619, 2948, 632])) THEN
                            CASE
                                WHEN ((classification_type.code)::integer > 3) THEN ((3)::text)::character varying
                                ELSE classification_type.code
                            END
                            ELSE classification_type.code
                        END
                        ELSE '0'::character varying
                    END)::text
                    ELSE '6'::text
                END AS cls_code
           FROM ((((public.surface_water_body swb
             LEFT JOIN public.hydro_object ON ((hydro_object.hdo_id = swb.swb_id)))
             LEFT JOIN public.wfd_qe_swtype ON (((swb.sw_target_typology_id = wfd_qe_swtype.swt_id) AND (wfd_qe_swtype.opt_id <> ALL (ARRAY[4477, 4520, 4480, 4476, 4479, 5892, 5893, 5891, 4514])))))
             LEFT JOIN oordeel_2009 ON (((oordeel_2009.swb_id = swb.swb_id) AND (oordeel_2009.opt_id = wfd_qe_swtype.opt_id))))
             LEFT JOIN public.classification_type ON ((classification_type.cls_id = oordeel_2009.cls_id)))
          WHERE (hydro_object.wkrv_id = 2)
        ), qe_2009 AS (
         SELECT DISTINCT ON (oordeel_qe_2009_1."euSurfaceWaterBodyCode", oordeel_qe_2009_1."qeCode") oordeel_qe_2009_1.swb_id,
            oordeel_qe_2009_1.opt_id,
            oordeel_qe_2009_1."qualityElementID",
            oordeel_qe_2009_1."euSurfaceWaterBodyCode",
            oordeel_qe_2009_1."qeCode",
            oordeel_qe_2009_1."qeStatusOrPotentialValue",
            oordeel_qe_2009_1."qeMonitoringResults",
            oordeel_qe_2009_1."qeMonitoringPeriod",
            oordeel_qe_2009_1.cls_code
           FROM oordeel_qe_2009 oordeel_qe_2009_1
          ORDER BY oordeel_qe_2009_1."euSurfaceWaterBodyCode", oordeel_qe_2009_1."qeCode", oordeel_qe_2009_1.cls_code
        )
 SELECT DISTINCT ON (oordeel_qe_2015."euSurfaceWaterBodyCode", oordeel_qe_2015."qeCode") oordeel_qe_2015."qualityElementID",
    oordeel_qe_2015."euSurfaceWaterBodyCode",
    oordeel_qe_2015."qeCode",
    oordeel_qe_2015."qeStatusOrPotentialValue",
    oordeel_qe_2015."qeMonitoringResults",
    oordeel_qe_2015."qeMonitoringPeriod",
        CASE
            WHEN ((oordeel_qe_2009.cls_code IS NULL) OR ((oordeel_qe_2009.cls_code)::integer = 0)) THEN 'Unknown2010'::text
            ELSE
            CASE
                WHEN ((oordeel_qe_2015.cls_code IS NULL) OR ((oordeel_qe_2015.cls_code)::integer = 0) OR ((oordeel_qe_2015.cls_code)::integer = 6)) THEN NULL::text
                ELSE
                CASE ((oordeel_qe_2015.cls_code)::integer - (oordeel_qe_2009.cls_code)::integer)
                    WHEN 1 THEN '+1'::text
                    ELSE 'oeps'::text
                END
            END
        END AS "qeStatusOrPotentialChange",
        CASE
            WHEN ((oordeel_qe_2009.cls_code IS NULL) OR ((oordeel_qe_2009.cls_code)::integer = 0)) THEN NULL::text
            ELSE
            CASE
                WHEN ((oordeel_qe_2015.cls_code IS NULL) OR ((oordeel_qe_2015.cls_code)::integer = 0) OR ((oordeel_qe_2015.cls_code)::integer = 6)) THEN NULL::text
                ELSE
                CASE
                    WHEN (((oordeel_qe_2015.cls_code)::integer - (oordeel_qe_2009.cls_code)::integer) = 0) THEN NULL::text
                    ELSE
                    CASE scm.scm_id
                        WHEN 1 THEN 'Consistent change'::text
                        WHEN 2 THEN 'Inconsistent due to changes to monitoring'::text
                        WHEN 3 THEN 'Inconsistent due to changes to assessment methods'::text
                        WHEN 4 THEN 'Inconsistent due to changes to monitoring and assessment methods'::text
                        ELSE 'No information or unknown'::text
                    END
                END
            END
        END AS "qeStatusOrPotentialComparability"
   FROM ((((oordeel_qe_2015
     LEFT JOIN public.related_hydro_object rho ON (((rho.from_hdo = oordeel_qe_2015.swb_id) AND (rho.rrt_id = 9))))
     LEFT JOIN public.wb_status_change_motivation wsc ON (((wsc.wbd_id = oordeel_qe_2015.swb_id) AND (wsc.opt_id = oordeel_qe_2015.opt_id) AND (wsc.year_status = 2015) AND (wsc.year_initial = 2009))))
     LEFT JOIN domains.status_change_motivation_type scm ON ((wsc.scm_id = scm.scm_id)))
     LEFT JOIN oordeel_qe_2009 ON (((oordeel_qe_2009.swb_id = rho.to_hdo) AND (oordeel_qe_2009.opt_id = oordeel_qe_2015.opt_id))))
  ORDER BY oordeel_qe_2015."euSurfaceWaterBodyCode", oordeel_qe_2015."qeCode", oordeel_qe_2015."qeStatusOrPotentialValue";


--
-- Name: vw_qualityelement_qexecologicalexemptiontype; Type: VIEW; Schema: wfd_reporting; Owner: -
--

CREATE VIEW vw_qualityelement_qexecologicalexemptiontype AS
 WITH oordeel_2015 AS (
         SELECT DISTINCT ON (swb.swb_id, ses.opt_id) swb.swb_id,
            ses.opt_id,
            ses.wbpm_id,
            hydro_object.inspire_id_local_id,
            ses.swes_id AS cls_id,
            swb.sw_target_typology_id
           FROM (((public.surface_water_body swb
             LEFT JOIN public.hydro_object ON ((hydro_object.hdo_id = swb.swb_id)))
             LEFT JOIN public.swb_yearly_status ON (((swb.swb_id = swb_yearly_status.swb_id) AND (swb_yearly_status.year_of_status = 2015))))
             LEFT JOIN public.sw_ecological_status ses ON (((ses.sys_id = swb_yearly_status.sys_id) AND (ses.opt_id = ANY (ARRAY[579, 3685, 4212, 3841, 3773, 619, 2948, 4507, 4515, 4521, 4482, 632])))))
          WHERE ((ses.eumg_id = 3) AND (hydro_object.wkrv_id = 13))
        UNION ALL
         SELECT DISTINCT ON (swb.swb_id, ses.opt_id) swb.swb_id,
            ses.opt_id,
            ses.wbpm_id,
            hydro_object.inspire_id_local_id,
            ses.swcs_id AS cls_id,
            swb.sw_target_typology_id
           FROM (((public.surface_water_body swb
             LEFT JOIN public.hydro_object ON ((hydro_object.hdo_id = swb.swb_id)))
             LEFT JOIN public.swb_yearly_status ON (((swb.swb_id = swb_yearly_status.swb_id) AND (swb_yearly_status.year_of_status = 2015))))
             LEFT JOIN public.sw_chemical_substance_status ses ON (((ses.sys_id = swb_yearly_status.sys_id) AND (ses.opt_id = 4519))))
          WHERE ((ses.eumg_id = 3) AND (hydro_object.wkrv_id = 13))
  ORDER BY 1, 2, 3 DESC
        ), oordeel_qe_2015 AS (
         SELECT swb.swb_id,
            wfd_qe_swtype.opt_id,
            ((swb.swb_id)::text || (wfd_qe_swtype.opt_id)::text) AS "qualityElementID",
            hydro_object.inspire_id_local_id AS "euSurfaceWaterBodyCode",
                CASE wfd_qe_swtype.opt_id
                    WHEN 579 THEN 'QE3-1-4 - Salinity conditions'::text
                    WHEN 619 THEN 'QE3-1-6-1 - Nitrogen conditions'::text
                    WHEN 2948 THEN 'QE3-1-6-1 - Nitrogen conditions'::text
                    WHEN 3685 THEN 'QE3-1-5 - Acidification status'::text
                    WHEN 4212 THEN 'QE3-1-3 - Oxygenation conditions'::text
                    WHEN 3841 THEN 'QE3-1-1 - Transparency conditions'::text
                    WHEN 3773 THEN 'QE3-1-2 - Thermal conditions'::text
                    WHEN 4519 THEN 'QE3-3 - River Basin Specific Pollutants'::text
                    WHEN 4507 THEN 'QE1-2-4 - Phytobenthos'::text
                    WHEN 4515 THEN 'QE1-2 - Other aquatic flora'::text
                    WHEN 4521 THEN 'QE1-4 - Fish'::text
                    WHEN 4482 THEN 'QE1-1 - Phytoplankton'::text
                    WHEN 632 THEN 'QE3-1-6-2 - Phosphorus Conditions'::text
                    ELSE NULL::text
                END AS "qeCode",
                CASE
                    WHEN (wfd_qe_swtype.is_applicable IS TRUE) THEN (
                    CASE
                        WHEN ((classification_type.code)::integer = ANY (ARRAY[1, 2, 3, 4, 5])) THEN
                        CASE
                            WHEN (wfd_qe_swtype.opt_id = ANY (ARRAY[579, 3685, 4212, 3841, 3773, 4519, 619, 2948, 632])) THEN
                            CASE
                                WHEN ((classification_type.code)::integer > 3) THEN ((3)::text)::character varying
                                ELSE classification_type.code
                            END
                            ELSE classification_type.code
                        END
                        ELSE '0'::character varying
                    END)::text
                    ELSE '6'::text
                END AS cls_code
           FROM ((((public.surface_water_body swb
             LEFT JOIN public.hydro_object ON ((hydro_object.hdo_id = swb.swb_id)))
             LEFT JOIN public.wfd_qe_swtype ON (((swb.sw_target_typology_id = wfd_qe_swtype.swt_id) AND (wfd_qe_swtype.opt_id <> ALL (ARRAY[4477, 4520, 4480, 4476, 4479, 5892, 5893, 5891, 4514])))))
             LEFT JOIN oordeel_2015 ON (((oordeel_2015.swb_id = swb.swb_id) AND (oordeel_2015.opt_id = wfd_qe_swtype.opt_id))))
             LEFT JOIN public.classification_type ON ((classification_type.cls_id = oordeel_2015.cls_id)))
          WHERE (hydro_object.wkrv_id = 13)
        ), qe_2015 AS (
         SELECT DISTINCT ON (oordeel_qe_2015_1."euSurfaceWaterBodyCode", oordeel_qe_2015_1."qeCode") oordeel_qe_2015_1.swb_id,
            oordeel_qe_2015_1.opt_id,
            oordeel_qe_2015_1.opt_id AS "qualityElementID",
            oordeel_qe_2015_1."euSurfaceWaterBodyCode",
            oordeel_qe_2015_1."qeCode",
            oordeel_qe_2015_1.cls_code
           FROM oordeel_qe_2015 oordeel_qe_2015_1
          ORDER BY oordeel_qe_2015_1."euSurfaceWaterBodyCode", oordeel_qe_2015_1."qeCode", oordeel_qe_2015_1.cls_code
        ), oordeel_2009 AS (
         SELECT DISTINCT ON (swb.swb_id, ses.opt_id) swb.swb_id,
            ses.opt_id,
            ses.wbpm_id,
            hydro_object.inspire_id_local_id,
            ses.swes_id AS cls_id,
            swb.sw_target_typology_id
           FROM (((public.surface_water_body swb
             LEFT JOIN public.hydro_object ON ((hydro_object.hdo_id = swb.swb_id)))
             LEFT JOIN public.swb_yearly_status ON (((swb.swb_id = swb_yearly_status.swb_id) AND (swb_yearly_status.year_of_status = 2009))))
             LEFT JOIN public.sw_ecological_status ses ON (((ses.sys_id = swb_yearly_status.sys_id) AND (ses.opt_id = ANY (ARRAY[579, 3685, 4212, 3841, 3773, 619, 2948, 4507, 4515, 4521, 4482, 632])))))
          WHERE ((ses.eumg_id = 3) AND (hydro_object.wkrv_id = 2))
        UNION ALL
         SELECT DISTINCT ON (swb.swb_id, ses.opt_id) swb.swb_id,
            ses.opt_id,
            ses.wbpm_id,
            hydro_object.inspire_id_local_id,
            ses.swcs_id AS cls_id,
            swb.sw_target_typology_id
           FROM (((public.surface_water_body swb
             LEFT JOIN public.hydro_object ON ((hydro_object.hdo_id = swb.swb_id)))
             LEFT JOIN public.swb_yearly_status ON (((swb.swb_id = swb_yearly_status.swb_id) AND (swb_yearly_status.year_of_status = 2009))))
             LEFT JOIN public.sw_chemical_substance_status ses ON (((ses.sys_id = swb_yearly_status.sys_id) AND (ses.opt_id = 4519))))
          WHERE ((ses.eumg_id = 3) AND (hydro_object.wkrv_id = 2))
  ORDER BY 1, 2, 3 DESC
        ), oordeel_qe_2009 AS (
         SELECT swb.swb_id,
            wfd_qe_swtype.opt_id,
            ((swb.swb_id)::text || (wfd_qe_swtype.opt_id)::text) AS "qualityElementID",
            hydro_object.inspire_id_local_id AS "euSurfaceWaterBodyCode",
                CASE wfd_qe_swtype.opt_id
                    WHEN 579 THEN 'QE3-1-4 - Salinity conditions'::text
                    WHEN 619 THEN 'QE3-1-6-1 - Nitrogen conditions'::text
                    WHEN 2948 THEN 'QE3-1-6-1 - Nitrogen conditions'::text
                    WHEN 3685 THEN 'QE3-1-5 - Acidification status'::text
                    WHEN 4212 THEN 'QE3-1-3 - Oxygenation conditions'::text
                    WHEN 3841 THEN 'QE3-1-1 - Transparency conditions'::text
                    WHEN 3773 THEN 'QE3-1-2 - Thermal conditions'::text
                    WHEN 4519 THEN 'QE3-3 - River Basin Specific Pollutants'::text
                    WHEN 4507 THEN 'QE1-3 – Benthic invertebrates'::text
                    WHEN 4515 THEN 'QE1-2 - Other aquatic flora'::text
                    WHEN 4521 THEN 'QE1-4 - Fish'::text
                    WHEN 4482 THEN 'QE1-1 - Phytoplankton'::text
                    WHEN 632 THEN 'QE3-1-6-2 - Phosphorus Conditions'::text
                    ELSE NULL::text
                END AS "qeCode",
                CASE
                    WHEN (wfd_qe_swtype.is_applicable IS TRUE) THEN (
                    CASE
                        WHEN ((classification_type.code)::integer = ANY (ARRAY[1, 2, 3, 4, 5])) THEN
                        CASE
                            WHEN (wfd_qe_swtype.opt_id = ANY (ARRAY[579, 3685, 4212, 3841, 3773, 4519, 619, 2948, 632])) THEN
                            CASE
                                WHEN ((classification_type.code)::integer > 3) THEN ((3)::text)::character varying
                                ELSE classification_type.code
                            END
                            ELSE classification_type.code
                        END
                        ELSE 'Unknown'::character varying
                    END)::text
                    ELSE 'Not applicable'::text
                END AS "qeStatusOrPotentialValue",
                CASE
                    WHEN (wfd_qe_swtype.is_applicable IS TRUE) THEN
                    CASE
                        WHEN (oordeel_2009.wbpm_id = 1) THEN 'Monitoring'::text
                        ELSE 'Expert judgement'::text
                    END
                    ELSE NULL::text
                END AS "qeMonitoringResults",
                CASE
                    WHEN (wfd_qe_swtype.is_applicable IS TRUE) THEN
                    CASE
                        WHEN (oordeel_2009.wbpm_id = 1) THEN '2009-2014'::text
                        ELSE NULL::text
                    END
                    ELSE NULL::text
                END AS "qeMonitoringPeriod",
                CASE
                    WHEN (wfd_qe_swtype.is_applicable IS TRUE) THEN (
                    CASE
                        WHEN ((classification_type.code)::integer = ANY (ARRAY[1, 2, 3, 4, 5])) THEN
                        CASE
                            WHEN (wfd_qe_swtype.opt_id = ANY (ARRAY[579, 3685, 4212, 3841, 3773, 4519, 619, 2948, 632])) THEN
                            CASE
                                WHEN ((classification_type.code)::integer > 3) THEN ((3)::text)::character varying
                                ELSE classification_type.code
                            END
                            ELSE classification_type.code
                        END
                        ELSE '0'::character varying
                    END)::text
                    ELSE '6'::text
                END AS cls_code
           FROM ((((public.surface_water_body swb
             LEFT JOIN public.hydro_object ON ((hydro_object.hdo_id = swb.swb_id)))
             LEFT JOIN public.wfd_qe_swtype ON (((swb.sw_target_typology_id = wfd_qe_swtype.swt_id) AND (wfd_qe_swtype.opt_id <> ALL (ARRAY[4477, 4520, 4480, 4476, 4479, 5892, 5893, 5891, 4514])))))
             LEFT JOIN oordeel_2009 ON (((oordeel_2009.swb_id = swb.swb_id) AND (oordeel_2009.opt_id = wfd_qe_swtype.opt_id))))
             LEFT JOIN public.classification_type ON ((classification_type.cls_id = oordeel_2009.cls_id)))
          WHERE (hydro_object.wkrv_id = 2)
        ), qe_2009 AS (
         SELECT DISTINCT ON (oordeel_qe_2009_1."euSurfaceWaterBodyCode", oordeel_qe_2009_1."qeCode") oordeel_qe_2009_1.swb_id,
            oordeel_qe_2009_1.opt_id,
            oordeel_qe_2009_1."qualityElementID",
            oordeel_qe_2009_1."euSurfaceWaterBodyCode",
            oordeel_qe_2009_1."qeCode",
            oordeel_qe_2009_1."qeStatusOrPotentialValue",
            oordeel_qe_2009_1."qeMonitoringResults",
            oordeel_qe_2009_1."qeMonitoringPeriod",
            oordeel_qe_2009_1.cls_code
           FROM oordeel_qe_2009 oordeel_qe_2009_1
          ORDER BY oordeel_qe_2009_1."euSurfaceWaterBodyCode", oordeel_qe_2009_1."qeCode", oordeel_qe_2009_1.cls_code
        )
 SELECT DISTINCT ON (oordeel_qe_2015.swb_id, oordeel_qe_2015.opt_id, gwce.obex_id) oordeel_qe_2015."qualityElementID",
        CASE
            WHEN (objectives_exemption_type.description IS NULL) THEN 'No exemption'::text
            ELSE objectives_exemption_type.description
        END AS "qeEcologicalExemptionType"
   FROM (((((oordeel_qe_2015
     LEFT JOIN public.related_hydro_object rho ON (((rho.from_hdo = oordeel_qe_2015.swb_id) AND (rho.rrt_id = 9))))
     LEFT JOIN public.swb_exemption gwce ON ((gwce.swb_id = oordeel_qe_2015.swb_id)))
     LEFT JOIN public.swb_ecol_exemp_qe gce ON (((gce.swce_id = gwce.swce_id) AND ((oordeel_qe_2015.opt_id = gce.opt_id) OR (gce.opt_id = ANY (ARRAY[4479, 4480, 4476, 4514]))))))
     LEFT JOIN public.objectives_exemption_type ON ((objectives_exemption_type.obex_id = gwce.obex_id)))
     LEFT JOIN oordeel_qe_2009 ON (((oordeel_qe_2009.swb_id = rho.to_hdo) AND (oordeel_qe_2009.opt_id = oordeel_qe_2015.opt_id))))
  WHERE ((oordeel_qe_2015.cls_code)::integer <> ALL (ARRAY[0, 1, 6]))
  ORDER BY oordeel_qe_2015.swb_id, oordeel_qe_2015.opt_id, gwce.obex_id;


--
-- Name: vw_rbd; Type: VIEW; Schema: wfd_reporting; Owner: -
--

CREATE VIEW vw_rbd AS
 WITH ktypen AS (
         SELECT surface_water_body.area_value,
            water_body.rbd_id,
            "left"((hydro_object.inspire_id_local_id)::text, 4) AS rbd,
            sw_typology_type.code
           FROM public.water_body,
            public.surface_water_body,
            public.sw_typology_type,
            public.hydro_object
          WHERE ((water_body.wbd_id = surface_water_body.swb_id) AND (sw_typology_type.styp_id = surface_water_body.sw_typology_id) AND (hydro_object.hdo_id = water_body.rbd_id) AND ((sw_typology_type.code)::text ~~ 'K%'::text) AND (hydro_object.wkrv_id = 13))
        ), ktypen_opp AS (
         SELECT ktypen.rbd,
            ((10)::double precision * floor((sum(ktypen.area_value) / (10)::double precision))) AS opp
           FROM ktypen
          GROUP BY ktypen.rbd
        )
 SELECT hdo.inspire_id_local_id AS "euRBDCode",
    hdo.hdo_id AS "rBDSUCAID",
        CASE hdo_names.name
            WHEN 'Eems'::text THEN 'Dutch Ems'::text
            WHEN 'Maas'::text THEN 'Dutch Meuse'::text
            WHEN 'Rijn'::text THEN 'Dutch Rhine'::text
            WHEN 'Schelde'::text THEN 'Dutch Scheldt'::text
            ELSE 'oeps'::text
        END AS "rbdName",
    rbd.area_value AS "rbdArea",
        CASE
            WHEN (ktypen_opp.opp IS NULL) THEN rbd.area_value
            ELSE (rbd.area_value - ktypen_opp.opp)
        END AS "rbdAreaExclCW",
    'Yes'::text AS "internationalRBD",
        CASE hdo_names.name
            WHEN 'Eems'::text THEN 'Ems'::text
            WHEN 'Maas'::text THEN 'Meuse'::text
            WHEN 'Rijn'::text THEN 'Rhine'::text
            WHEN 'Schelde'::text THEN 'Scheldt'::text
            ELSE 'oeps'::text
        END AS "internationalRBDName",
    'No'::text AS "subUnitsDefined",
    'NL_MINIM'::text AS "primeCompetentAuthority"
   FROM (((public.hydro_object hdo
     LEFT JOIN public.hdo_names ON ((hdo_names.hdo_id = hdo.hdo_id)))
     LEFT JOIN public.river_basin_disrict rbd ON ((hdo.hdo_id = rbd.rbd_id)))
     LEFT JOIN ktypen_opp ON ((ktypen_opp.rbd = (hdo.inspire_id_local_id)::text)))
  WHERE ((hdo.wkrv_id = 13) AND (length((hdo.inspire_id_local_id)::text) = 4) AND ((hdo.hydro_object_type)::text = 'RiverBasinDistrict'::text));


--
-- Name: vw_rbd_othercompetentauthority; Type: VIEW; Schema: wfd_reporting; Owner: -
--

CREATE VIEW vw_rbd_othercompetentauthority AS
 SELECT DISTINCT ON (("left"((rbd.inspire_id_local_id)::text, 4)), organisatorische_eenheid.organisatie_identificatie) "left"((rbd.inspire_id_local_id)::text, 4) AS "euRBDCode",
    organisatorische_eenheid.organisatie_identificatie AS "otherCompetentAuthority"
   FROM public.hydro_object,
    public.organisatorische_eenheid,
    public.competent_authority,
    public.competentauthority_namespacetype,
    public.namespace_type,
    public.water_body,
    public.hydro_object rbd
  WHERE ((competent_authority.ore_id = organisatorische_eenheid.ore_id) AND (competentauthority_namespacetype.ore_id = competent_authority.ore_id) AND (competentauthority_namespacetype.ns_id = namespace_type.ns_id) AND (namespace_type.ns_id = hydro_object.inspire_id_namespace) AND (water_body.wbd_id = hydro_object.hdo_id) AND (rbd.hdo_id = water_body.rbd_id) AND (hydro_object.wkrv_id = 13) AND ((organisatorische_eenheid.organisatie_identificatie)::text <> 'NL_MINIM'::text))
  ORDER BY ("left"((rbd.inspire_id_local_id)::text, 4)), organisatorische_eenheid.organisatie_identificatie;


--
-- Name: vw_surfacewaterbody; Type: VIEW; Schema: wfd_reporting; Owner: -
--

CREATE VIEW vw_surfacewaterbody AS
 WITH mpn AS (
         SELECT DISTINCT ON (mpn.repr_owm, mpn.ligt_in_owm) mpn.repr_owm,
            mpn.ligt_in_owm
           FROM eu_state_of_environment.monprog_2015 mpn
          WHERE (((mpn.montype)::text = 'ow'::text) AND ((mpn.parameter)::text <> ALL (ARRAY[('STIJGHTE'::character varying)::text, ('Ntot'::character varying)::text, ('Ptot'::character varying)::text, ('Nanorg'::character varying)::text, ('O'::character varying)::text, ('Cl'::character varying)::text, ('FYTOBEN'::character varying)::text, ('FYTOPL'::character varying)::text, ('VIS'::character varying)::text, ('OVWFLORA'::character varying)::text, ('STOFOV'::character varying)::text, ('MAFAUNA'::character varying)::text, ('ZICHT'::character varying)::text, ('pH'::character varying)::text, ('SALNTT'::character varying)::text, ('STORPR'::character varying)::text, ('CHEMT'::character varying)::text, ('NO2'::character varying)::text, ('NO3'::character varying)::text, ('NH4'::character varying)::text, ('NKj'::character varying)::text])) AND ((mpn.parameter)::text !~~ 'HMF%'::text) AND ((mpn.ligt_in_owm)::text <> (mpn.repr_owm)::text))
          ORDER BY mpn.repr_owm
        ), mpn2 AS (
         SELECT mpn.repr_owm,
                CASE
                    WHEN (hdo_f.inspire_id_local_id IS NULL) THEN mpn.ligt_in_owm
                    ELSE hdo_f.inspire_id_local_id
                END AS ligt_in
           FROM ((mpn
             JOIN public.hydro_object hdo_r ON ((((mpn.repr_owm)::text = (hdo_r.inspire_id_local_id)::text) AND (hdo_r.wkrv_id = 13) AND ((hdo_r.hydro_object_type)::text = ANY (ARRAY[('SurfaceWaterBody'::character varying)::text, ('GroundWaterBody'::character varying)::text])))))
             LEFT JOIN (public.hydro_object hdo_t
             JOIN (public.related_hydro_object rho
             JOIN public.hydro_object hdo_f ON (((hdo_f.hdo_id = rho.from_hdo) AND ((hdo_f.hydro_object_type)::text = ANY (ARRAY[('SurfaceWaterBody'::character varying)::text, ('GroundWaterBody'::character varying)::text]))))) ON (((rho.to_hdo = hdo_t.hdo_id) AND (rho.rrt_id = 2) AND (hdo_f.wkrv_id = 13)))) ON ((((hdo_t.inspire_id_local_id)::text = (mpn.ligt_in_owm)::text) AND (hdo_t.wkrv_id = 2) AND ((hdo_t.hydro_object_type)::text = ANY (ARRAY[('SurfaceWaterBody'::character varying)::text, ('GroundWaterBody'::character varying)::text])))))
          WHERE (((hdo_f.inspire_id_local_id)::text <> (mpn.repr_owm)::text) AND (hdo_f.inspire_id_local_id IS NOT NULL))
        ), "grouping" AS (
         SELECT DISTINCT ON (mpn2.repr_owm) mpn2.repr_owm,
            mpn2.ligt_in
           FROM mpn2
          ORDER BY mpn2.repr_owm
        ), swb_prot AS (
         SELECT DISTINCT ON (wpi.wbd_id) wpi.wbd_id
           FROM public.waterbody_protected_area_intersection wpi,
            public.wfd_protected_area,
            public.hydro_object hydro_object_1
          WHERE ((wfd_protected_area.wpa_id = wpi.wpa_id) AND (wfd_protected_area.protected_area_type_id = ANY (ARRAY[1, 4])) AND (hydro_object_1.hdo_id = wpi.wbd_id) AND (hydro_object_1.wkrv_id = 13) AND ((hydro_object_1.hydro_object_type)::text = 'SurfaceWaterBody'::text))
          ORDER BY wpi.wbd_id
        ), swb_oordeel AS (
         SELECT DISTINCT ON (hdo_swb.hdo_id, swb_yearly_status.year_of_status, sw_chemical_substance_status.opt_id) hdo_swb.hdo_id AS swb_id,
            swb_yearly_status.year_of_status AS jaar,
            sw_chemical_substance_status.opt_id,
            classification_type.description AS oordeel,
            waarde_bepalings_methode_type.code AS wbpm
           FROM (((((public.swb_yearly_status
             LEFT JOIN public.hydro_object hdo_swb ON ((hdo_swb.hdo_id = swb_yearly_status.swb_id)))
             JOIN public.sw_chemical_substance_status ON ((sw_chemical_substance_status.sys_id = swb_yearly_status.sys_id)))
             LEFT JOIN public.classification_type ON ((sw_chemical_substance_status.swcs_id = classification_type.cls_id)))
             LEFT JOIN public.vw_waargenomen_eigenschap ON ((vw_waargenomen_eigenschap."DB_ID" = sw_chemical_substance_status.opt_id)))
             LEFT JOIN public.waarde_bepalings_methode_type ON ((waarde_bepalings_methode_type.wbpm_id = sw_chemical_substance_status.wbpm_id)))
          WHERE ((hdo_swb.wkrv_id = 13) AND (swb_yearly_status.year_of_status = 2015) AND (sw_chemical_substance_status.opt_id = 4477))
        UNION ALL
         SELECT DISTINCT ON (hdo_swb.hdo_id, swb_yearly_status.year_of_status, sw_ecological_status.opt_id) hdo_swb.hdo_id AS swb_id,
            swb_yearly_status.year_of_status AS jaar,
            sw_ecological_status.opt_id,
            classification_type.description AS oordeel,
            waarde_bepalings_methode_type.code AS wbpm
           FROM (((((public.swb_yearly_status
             LEFT JOIN public.hydro_object hdo_swb ON ((hdo_swb.hdo_id = swb_yearly_status.swb_id)))
             JOIN public.sw_ecological_status ON ((sw_ecological_status.sys_id = swb_yearly_status.sys_id)))
             LEFT JOIN public.classification_type ON ((sw_ecological_status.swes_id = classification_type.cls_id)))
             LEFT JOIN public.vw_waargenomen_eigenschap ON ((vw_waargenomen_eigenschap."DB_ID" = sw_ecological_status.opt_id)))
             LEFT JOIN public.waarde_bepalings_methode_type ON ((waarde_bepalings_methode_type.wbpm_id = sw_ecological_status.wbpm_id)))
          WHERE ((hdo_swb.wkrv_id = 13) AND (swb_yearly_status.year_of_status = 2015) AND (sw_ecological_status.opt_id = 4479))
  ORDER BY 1, 2, 3, 5 DESC
        ), pressure AS (
         SELECT DISTINCT ON (hydro_object_1.hdo_id, spe.eu_xsd) hydro_object_1.hdo_id AS db_id,
            hydro_object_1.inspire_id_local_id AS "euSurfaceWaterBodyCode",
                CASE
                    WHEN (spe.eu_xsd IS NULL) THEN 'No significant pressure'::text
                    ELSE spe.eu_xsd
                END AS pressure_type
           FROM ((public.hydro_object hydro_object_1
             LEFT JOIN public.swb_pressure ON ((hydro_object_1.hdo_id = swb_pressure.swb_id)))
             LEFT JOIN significant_pressure_enum spe ON (((spe.sw_p_id = swb_pressure.sprs_id) AND (spe.eu_xsd ~~ '7 - %'::text))))
          WHERE ((swb_pressure.is_significant = true) AND (hydro_object_1.wkrv_id = 13))
          ORDER BY hydro_object_1.hdo_id, spe.eu_xsd
        ), swb_oordeel_i AS (
         SELECT DISTINCT ON (swb_oordeel.swb_id) swb_oordeel.swb_id,
            swb_oordeel.jaar,
            swb_oordeel.oordeel,
            swb_oordeel.wbpm
           FROM swb_oordeel
          ORDER BY swb_oordeel.swb_id, swb_oordeel.oordeel DESC
        ), impact AS (
         SELECT DISTINCT ON (hydro_object_1.hdo_id, ipe.eu_xsd) hydro_object_1.hdo_id AS db_id,
                CASE
                    WHEN (ipe.eu_xsd IS NULL) THEN
                    CASE
                        WHEN (((swb_oordeel_i.oordeel)::text = 'voldoet'::text) OR ((swb_oordeel_i.oordeel)::text = 'goed'::text) OR ((swb_oordeel_i.oordeel)::text = 'zeer goed'::text)) THEN 'NOSI - No significant impact'::text
                        ELSE 'UNKN - Unknown impact type'::text
                    END
                    ELSE ipe.eu_xsd
                END AS impact_type
           FROM ((((public.hydro_object hydro_object_1
             LEFT JOIN public.swb_pressure ON (((hydro_object_1.hdo_id = swb_pressure.swb_id) AND (swb_pressure.is_significant = true))))
             LEFT JOIN public.swb_pressure_impact ON ((swb_pressure.swbp_id = swb_pressure_impact.swbp_id)))
             LEFT JOIN significant_impact_enum ipe ON (((ipe.i_id = swb_pressure_impact.impact_id) AND (ipe.eu_xsd ~~ 'OTHE%'::text))))
             LEFT JOIN swb_oordeel_i ON ((swb_oordeel_i.swb_id = hydro_object_1.hdo_id)))
          WHERE ((hydro_object_1.wkrv_id = 13) AND ((hydro_object_1.hydro_object_type)::text = 'SurfaceWaterBody'::text))
          ORDER BY hydro_object_1.hdo_id, ipe.eu_xsd
        )
 SELECT hydro_object.hdo_id AS db_id,
    hydro_object.inspire_id_local_id AS "euSurfaceWaterBodyCode",
    "left"((hdo_rbd.inspire_id_local_id)::text, 4) AS "euRBDCode",
    NULL::text AS "euSubUnitCode",
    hdo_names.name AS "surfacewaterBodyName",
        CASE "left"((stt.code)::text, 1)
            WHEN 'K'::text THEN 'CW'::text
            WHEN 'O'::text THEN 'TW'::text
            WHEN 'M'::text THEN 'LW'::text
            WHEN 'R'::text THEN 'RW'::text
            ELSE 'oeps'::text
        END AS "surfaceWaterBodyTypeCategory",
        CASE
            WHEN (surface_water_body.is_artificial = true) THEN 'Artificial'::text
            WHEN (surface_water_body.is_heaviliy_modified = true) THEN 'Heavily Modified'::text
            ELSE 'Natural'::text
        END AS "naturalAWBHMWB",
        CASE
            WHEN (surface_water_body.is_heaviliy_modified = true) THEN 'No'::text
            ELSE NULL::text
        END AS reservoir,
    stt.code AS "surfaceWaterBodyTypeCode",
    icalt.eu_xsd AS "surfaceWaterBodyIntercalibrationType",
    'No'::text AS "surfaceWaterBodyTransboundary",
        CASE
            WHEN (gpb.wbd_id IS NULL) THEN 'False'::text
            ELSE 'True'::text
        END AS "swAssociatedProtectedArea",
        CASE
            WHEN (pressure.pressure_type ~~ '7 - %'::text) THEN surface_water_body.other_pressure_description
            ELSE NULL::character varying
        END AS "swSignificantPressureOther",
        CASE
            WHEN (impact.impact_type ~~ 'OTHE%'::text) THEN 'No further details available'::text
            ELSE NULL::text
        END AS "swSignificantImpactOther",
        CASE goq.oordeel
            WHEN 'goed'::text THEN 2
            WHEN 'matig'::text THEN 3
            WHEN 'ontoereikend'::text THEN 4
            ELSE 5
        END AS "swEcologicalStatusOrPotentialValue",
    '2009-2014'::text AS "swEcologicalAssessmentYear",
        CASE goq.wbpm
            WHEN 'AQUOKIT'::text THEN 3
            ELSE 2
        END AS "swEcologicalAssessmentConfidence",
        CASE
            WHEN ((goq.oordeel)::text = 'goed'::text) THEN 'Yes'::text
            ELSE 'No'::text
        END AS "swEcologicalStatusExpectedGoodIn2015",
        CASE
            WHEN ((goq.oordeel)::text = 'goed'::text) THEN NULL::text
            ELSE
            CASE
                WHEN (spe2021.cls_id = 4) THEN '2016-2021'::text
                ELSE
                CASE
                    WHEN ((spe2027.cls_id = 4) OR (spe2027.cls_id IS NULL)) THEN '2022-2027'::text
                    ELSE 'Beyond 2027'::text
                END
            END
        END AS "swEcologicalStatusExpectedAchievementDate",
        CASE
            WHEN (ups.local_id IS NULL) THEN
            CASE
                WHEN ((goc.oordeel)::text = 'voldoet'::text) THEN 2
                ELSE 3
            END
            ELSE 1
        END AS "swChemicalStatusValue",
    '2009-2014'::text AS "swChemicalAssessmentYear",
        CASE
            WHEN (ups.local_id IS NULL) THEN
            CASE goq.wbpm
                WHEN 'AQUOKIT'::text THEN 3
                ELSE 2
            END
            ELSE NULL::integer
        END AS "swChemicalAssessmentConfidence",
        CASE
            WHEN ((goq.wbpm)::text = 'DESK'::text) THEN 'Expert judgement'::text
            ELSE
            CASE
                WHEN ("grouping".repr_owm IS NULL) THEN 'Monitoring'::text
                ELSE 'Grouping'::text
            END
        END AS swchemicalmonitoringresults,
        CASE
            WHEN ((goc.oordeel)::text = 'voldoet'::text) THEN 'Yes'::text
            ELSE 'No'::text
        END AS "swChemicalStatusExpectedGoodIn2015",
        CASE
            WHEN ((goc.oordeel)::text = 'voldoet'::text) THEN NULL::text
            ELSE
            CASE
                WHEN (spc2021.cls_id = 1) THEN '2016-2021'::text
                ELSE
                CASE
                    WHEN ((spc2027.cls_id = 1) OR (spc2027.cls_id IS NULL)) THEN '2022-2027'::text
                    ELSE 'Beyond 2027'::text
                END
            END
        END AS "swChemicalStatusExpectedAchievementDate",
    'No'::text AS "swMixingZones",
    NULL::integer AS "swMixingZonesProportion"
   FROM ((((((((((((((((((public.hydro_object
     LEFT JOIN public.hdo_names ON ((hdo_names.hdo_id = hydro_object.hdo_id)))
     JOIN public.water_body ON ((water_body.wbd_id = hydro_object.hdo_id)))
     JOIN public.surface_water_body ON ((surface_water_body.swb_id = hydro_object.hdo_id)))
     JOIN public.sw_typology_type stt ON ((stt.styp_id = surface_water_body.sw_typology_id)))
     JOIN public.river_basin_disrict rbd ON ((rbd.rbd_id = water_body.rbd_id)))
     JOIN public.hydro_object hdo_rbd ON ((rbd.rbd_id = hdo_rbd.hdo_id)))
     LEFT JOIN swb_prot gpb ON ((gpb.wbd_id = hydro_object.hdo_id)))
     LEFT JOIN public.wb_prognosis spe2021 ON (((spe2021.swb_id = hydro_object.hdo_id) AND (spe2021.opt_id = 4479) AND (spe2021.year = 2021))))
     LEFT JOIN public.wb_prognosis spe2027 ON (((spe2027.swb_id = hydro_object.hdo_id) AND (spe2027.opt_id = 4479) AND (spe2027.year = 2027))))
     LEFT JOIN public.wb_prognosis spc2021 ON (((spc2021.swb_id = hydro_object.hdo_id) AND (spc2021.opt_id = 4477) AND (spc2021.year = 2021))))
     LEFT JOIN public.wb_prognosis spc2027 ON (((spc2027.swb_id = hydro_object.hdo_id) AND (spc2027.opt_id = 4477) AND (spc2027.year = 2027))))
     LEFT JOIN swb_oordeel goc ON (((goc.swb_id = hydro_object.hdo_id) AND (goc.opt_id = 4477))))
     LEFT JOIN swb_oordeel goq ON (((goq.swb_id = hydro_object.hdo_id) AND (goq.opt_id = 4479))))
     LEFT JOIN pressure ON (((pressure.db_id = hydro_object.hdo_id) AND (pressure.pressure_type ~~ '7 - %'::text))))
     LEFT JOIN impact ON (((impact.db_id = hydro_object.hdo_id) AND (impact.impact_type ~~ 'OTHE%'::text))))
     LEFT JOIN public.eu_intercalibration_type icalt ON ((icalt.icalt = stt.icalt_id)))
     LEFT JOIN swb_unknown_ps ups ON (((hydro_object.inspire_id_local_id)::text = (ups.local_id)::text)))
     LEFT JOIN "grouping" ON ((("grouping".repr_owm)::text = (hydro_object.inspire_id_local_id)::text)))
  WHERE (((hydro_object.hydro_object_type)::text = 'SurfaceWaterBody'::text) AND (hydro_object.wkrv_id = 13))
  ORDER BY hydro_object.inspire_id_local_id;


--
-- Name: vw_surfacewaterbody_hmwbphysicalalteration; Type: VIEW; Schema: wfd_reporting; Owner: -
--

CREATE VIEW vw_surfacewaterbody_hmwbphysicalalteration AS
 SELECT hydro_object.inspire_id_local_id AS "euSurfaceWaterBodyCode",
    physical_alteration_type.remark AS "hmwbPhysicalAlteration"
   FROM public.hydro_object,
    public.swb_physical_alteration,
    public.physical_alteration_type
  WHERE ((swb_physical_alteration.swb_id = hydro_object.hdo_id) AND (physical_alteration_type.pat_id = swb_physical_alteration.pat_id) AND (hydro_object.wkrv_id = 13))
  ORDER BY hydro_object.inspire_id_local_id;


--
-- Name: vw_surfacewaterbody_hmwbwateruse; Type: VIEW; Schema: wfd_reporting; Owner: -
--

CREATE VIEW vw_surfacewaterbody_hmwbwateruse AS
 SELECT hydro_object.inspire_id_local_id AS "euSurfaceWaterBodyCode",
        CASE eu_function_43a_type.fu43_id
            WHEN 1 THEN 'Wider environment - nature protection and other ecological uses'::text
            WHEN 2 THEN 'Transport - navigation / ports'::text
            WHEN 3 THEN 'Other'::text
            WHEN 4 THEN 'Flood protection'::text
            WHEN 5 THEN 'Other'::text
            ELSE 'oeps'::text
        END AS "hmwbWaterUse"
   FROM public.swb_measures_43a,
    public.hydro_object,
    public.eu_function_43a_type
  WHERE ((hydro_object.hdo_id = swb_measures_43a.swb_id) AND (eu_function_43a_type.fu43_id = swb_measures_43a.fu43_id) AND (hydro_object.wkrv_id = 13));


--
-- Name: vw_surfacewaterbody_swchemicalstatusgrouping; Type: VIEW; Schema: wfd_reporting; Owner: -
--

CREATE VIEW vw_surfacewaterbody_swchemicalstatusgrouping AS
 WITH mpn AS (
         SELECT DISTINCT ON (mpn.repr_owm, mpn.ligt_in_owm) mpn.repr_owm,
            mpn.ligt_in_owm
           FROM eu_state_of_environment.monprog_2015 mpn
          WHERE (((mpn.montype)::text = 'ow'::text) AND ((mpn.parameter)::text <> ALL (ARRAY[('STIJGHTE'::character varying)::text, ('Ntot'::character varying)::text, ('Ptot'::character varying)::text, ('Nanorg'::character varying)::text, ('O'::character varying)::text, ('Cl'::character varying)::text, ('FYTOBEN'::character varying)::text, ('FYTOPL'::character varying)::text, ('VIS'::character varying)::text, ('OVWFLORA'::character varying)::text, ('STOFOV'::character varying)::text, ('MAFAUNA'::character varying)::text, ('ZICHT'::character varying)::text, ('pH'::character varying)::text, ('SALNTT'::character varying)::text, ('STORPR'::character varying)::text, ('CHEMT'::character varying)::text, ('NO2'::character varying)::text, ('NO3'::character varying)::text, ('NH4'::character varying)::text, ('NKj'::character varying)::text])) AND ((mpn.parameter)::text !~~ 'HMF%'::text) AND ((mpn.ligt_in_owm)::text <> (mpn.repr_owm)::text))
          ORDER BY mpn.repr_owm
        ), mpn2 AS (
         SELECT mpn.repr_owm,
                CASE
                    WHEN (hdo_f.inspire_id_local_id IS NULL) THEN mpn.ligt_in_owm
                    ELSE hdo_f.inspire_id_local_id
                END AS ligt_in
           FROM ((mpn
             JOIN public.hydro_object hdo_r ON ((((mpn.repr_owm)::text = (hdo_r.inspire_id_local_id)::text) AND (hdo_r.wkrv_id = 13) AND ((hdo_r.hydro_object_type)::text = ANY (ARRAY[('SurfaceWaterBody'::character varying)::text, ('GroundWaterBody'::character varying)::text])))))
             LEFT JOIN (public.hydro_object hdo_t
             JOIN (public.related_hydro_object rho
             JOIN public.hydro_object hdo_f ON (((hdo_f.hdo_id = rho.from_hdo) AND ((hdo_f.hydro_object_type)::text = ANY (ARRAY[('SurfaceWaterBody'::character varying)::text, ('GroundWaterBody'::character varying)::text]))))) ON (((rho.to_hdo = hdo_t.hdo_id) AND (rho.rrt_id = 2) AND (hdo_f.wkrv_id = 13)))) ON ((((hdo_t.inspire_id_local_id)::text = (mpn.ligt_in_owm)::text) AND (hdo_t.wkrv_id = 2) AND ((hdo_t.hydro_object_type)::text = ANY (ARRAY[('SurfaceWaterBody'::character varying)::text, ('GroundWaterBody'::character varying)::text])))))
          WHERE (((hdo_f.inspire_id_local_id)::text <> (mpn.repr_owm)::text) AND (hdo_f.inspire_id_local_id IS NOT NULL))
        )
 SELECT DISTINCT ON (mpn2.repr_owm, mpn2.ligt_in) mpn2.repr_owm AS "euSurfaceWaterBodyCode",
    mpn2.ligt_in AS "swChemicalStatusGrouping"
   FROM mpn2
  ORDER BY mpn2.repr_owm;


--
-- Name: vw_surfacewaterbody_swsignificantimpacttype; Type: VIEW; Schema: wfd_reporting; Owner: -
--

CREATE VIEW vw_surfacewaterbody_swsignificantimpacttype AS
 WITH swb_oordeel_all AS (
         SELECT DISTINCT ON (hdo_swb.hdo_id, swb_yearly_status.year_of_status, sw_chemical_substance_status.opt_id) hdo_swb.hdo_id AS swb_id,
            swb_yearly_status.year_of_status AS jaar,
            sw_chemical_substance_status.opt_id,
                CASE classification_type.description
                    WHEN 'voldoet'::text THEN 'goed'::text
                    WHEN 'voldoet niet'::text THEN 'slecht'::text
                    ELSE NULL::text
                END AS oordeel,
            waarde_bepalings_methode_type.code AS wbpm,
            hdo_swb.inspire_id_local_id
           FROM (((((public.swb_yearly_status
             LEFT JOIN public.hydro_object hdo_swb ON ((hdo_swb.hdo_id = swb_yearly_status.swb_id)))
             JOIN public.sw_chemical_substance_status ON ((sw_chemical_substance_status.sys_id = swb_yearly_status.sys_id)))
             LEFT JOIN public.classification_type ON ((sw_chemical_substance_status.swcs_id = classification_type.cls_id)))
             LEFT JOIN public.vw_waargenomen_eigenschap ON ((vw_waargenomen_eigenschap."DB_ID" = sw_chemical_substance_status.opt_id)))
             LEFT JOIN public.waarde_bepalings_methode_type ON ((waarde_bepalings_methode_type.wbpm_id = sw_chemical_substance_status.wbpm_id)))
          WHERE ((hdo_swb.wkrv_id = 13) AND (swb_yearly_status.year_of_status = 2015) AND (sw_chemical_substance_status.opt_id = 4477))
        UNION ALL
         SELECT DISTINCT ON (hdo_swb.hdo_id, swb_yearly_status.year_of_status, sw_ecological_status.opt_id) hdo_swb.hdo_id AS swb_id,
            swb_yearly_status.year_of_status AS jaar,
            sw_ecological_status.opt_id,
            classification_type.description AS oordeel,
            waarde_bepalings_methode_type.code AS wbpm,
            hdo_swb.inspire_id_local_id
           FROM (((((public.swb_yearly_status
             LEFT JOIN public.hydro_object hdo_swb ON ((hdo_swb.hdo_id = swb_yearly_status.swb_id)))
             JOIN public.sw_ecological_status ON ((sw_ecological_status.sys_id = swb_yearly_status.sys_id)))
             LEFT JOIN public.classification_type ON ((sw_ecological_status.swes_id = classification_type.cls_id)))
             LEFT JOIN public.vw_waargenomen_eigenschap ON ((vw_waargenomen_eigenschap."DB_ID" = sw_ecological_status.opt_id)))
             LEFT JOIN public.waarde_bepalings_methode_type ON ((waarde_bepalings_methode_type.wbpm_id = sw_ecological_status.wbpm_id)))
          WHERE ((hdo_swb.wkrv_id = 13) AND (swb_yearly_status.year_of_status = 2015) AND (sw_ecological_status.opt_id = 4479))
  ORDER BY 1, 2, 3, 5 DESC
        ), swb_oordeel AS (
         SELECT DISTINCT ON (swb_oordeel_all.swb_id) swb_oordeel_all.swb_id,
            swb_oordeel_all.inspire_id_local_id,
            swb_oordeel_all.jaar,
            swb_oordeel_all.oordeel,
            swb_oordeel_all.wbpm
           FROM swb_oordeel_all
          ORDER BY swb_oordeel_all.swb_id, swb_oordeel_all.oordeel
        ), impact_ruw AS (
         SELECT hydro_object.hdo_id AS db_id,
            hydro_object.inspire_id_local_id AS "euSurfaceWaterBodyCode",
                CASE
                    WHEN (ipe.eu_xsd IS NULL) THEN
                    CASE
                        WHEN (swb_oordeel.oordeel = 'goed'::text) THEN 'NOSI - No significant impact'::text
                        ELSE 'UNKN - Unknown impact type'::text
                    END
                    ELSE ipe.eu_xsd
                END AS "swSignificantImpactType"
           FROM ((((public.hydro_object
             LEFT JOIN public.swb_pressure ON (((hydro_object.hdo_id = swb_pressure.swb_id) AND (swb_pressure.is_significant = true))))
             LEFT JOIN public.swb_pressure_impact ON ((swb_pressure.swbp_id = swb_pressure_impact.swbp_id)))
             LEFT JOIN significant_impact_enum ipe ON ((ipe.i_id = swb_pressure_impact.impact_id)))
             LEFT JOIN swb_oordeel ON ((swb_oordeel.swb_id = hydro_object.hdo_id)))
          WHERE ((hydro_object.wkrv_id = 13) AND ((hydro_object.hydro_object_type)::text = 'SurfaceWaterBody'::text))
        )
 SELECT DISTINCT ON (impact_ruw."euSurfaceWaterBodyCode", impact_ruw."swSignificantImpactType") impact_ruw."euSurfaceWaterBodyCode",
    impact_ruw."swSignificantImpactType"
   FROM impact_ruw
  ORDER BY impact_ruw."euSurfaceWaterBodyCode", impact_ruw."swSignificantImpactType";


--
-- Name: vw_surfacewaterbody_swsignificantpressuretype; Type: VIEW; Schema: wfd_reporting; Owner: -
--

CREATE VIEW vw_surfacewaterbody_swsignificantpressuretype AS
 WITH bel_aant AS (
         SELECT hydro_object_1.hdo_id AS db_id,
            count(spe_1.eu_xsd) AS aant
           FROM ((public.hydro_object hydro_object_1
             LEFT JOIN public.swb_pressure swb_pressure_1 ON ((hydro_object_1.hdo_id = swb_pressure_1.swb_id)))
             LEFT JOIN significant_pressure_enum spe_1 ON (((spe_1.sw_p_id = swb_pressure_1.sprs_id) AND (swb_pressure_1.is_significant = true))))
          GROUP BY hydro_object_1.hdo_id, hydro_object_1.wkrv_id, hydro_object_1.hydro_object_type
         HAVING ((hydro_object_1.wkrv_id = 13) AND ((hydro_object_1.hydro_object_type)::text = 'SurfaceWaterBody'::text))
        )
 SELECT DISTINCT ON (hydro_object.inspire_id_local_id, spe.eu_xsd) hydro_object.hdo_id AS db_id,
    hydro_object.inspire_id_local_id AS "euSurfaceWaterBodyCode",
        CASE
            WHEN (spe.eu_xsd IS NULL) THEN 'No significant pressure'::text
            ELSE spe.eu_xsd
        END AS "swSignificantPressureType"
   FROM (((public.hydro_object
     LEFT JOIN public.swb_pressure ON ((hydro_object.hdo_id = swb_pressure.swb_id)))
     LEFT JOIN significant_pressure_enum spe ON (((spe.sw_p_id = swb_pressure.sprs_id) AND (swb_pressure.is_significant = true))))
     LEFT JOIN bel_aant ON ((bel_aant.db_id = hydro_object.hdo_id)))
  WHERE ((hydro_object.wkrv_id = 13) AND ((hydro_object.hydro_object_type)::text = 'SurfaceWaterBody'::text) AND (((bel_aant.aant = 0) AND (spe.eu_xsd IS NULL)) OR ((bel_aant.aant > 0) AND (spe.eu_xsd IS NOT NULL))))
  ORDER BY hydro_object.inspire_id_local_id, spe.eu_xsd;


--
-- Name: vw_swassociatedprotectedarea; Type: VIEW; Schema: wfd_reporting; Owner: -
--

CREATE VIEW vw_swassociatedprotectedarea AS
 SELECT swb.hdo_id,
    wpa.inspire_id_local_id AS "euProtectedAreaCode",
    swb.inspire_id_local_id AS "euSurfaceWaterBodyCode",
        CASE protected_area_type.code
            WHEN 'HA'::text THEN 'Habitats'::text
            WHEN 'BI'::text THEN 'Birds'::text
            WHEN 'BW'::text THEN 'Bathing'::text
            WHEN 'SH'::text THEN 'Shellfish'::text
            WHEN 'FI'::text THEN 'Fish'::text
            ELSE 'oeps'::text
        END AS "protectedAreaType",
    'Overlapping / partly within Protected Area'::text AS "protectedAreaAssociationType",
        CASE protected_area_type.code
            WHEN 'HA'::text THEN 'Yes, some specific water objectives have been set to protect dependent habitats and species but work is still on-going to determine needs.'::text
            WHEN 'BI'::text THEN 'Yes, some specific water objectives have been set to protect dependent habitats and species but work is still on-going to determine needs.'::text
            WHEN 'BW'::text THEN NULL::text
            WHEN 'SH'::text THEN NULL::text
            WHEN 'FI'::text THEN NULL::text
            ELSE 'oeps'::text
        END AS "protectedAreaHabitatsBirdsObjectivesSet",
        CASE protected_area_type.code
            WHEN 'HA'::text THEN 'No information'::text
            WHEN 'BI'::text THEN 'No information'::text
            WHEN 'BW'::text THEN NULL::text
            WHEN 'SH'::text THEN NULL::text
            WHEN 'FI'::text THEN NULL::text
            ELSE 'oeps'::text
        END AS "protectedAreaHabitatsBirdsObjectivesMet",
    NULL::text AS "protectedAreaDrinkinswaterObjectivesSet",
    NULL::text AS "protectedAreaDrinkinswaterObjectivesMet",
        CASE protected_area_type.code
            WHEN 'HA'::text THEN NULL::text
            WHEN 'BI'::text THEN NULL::text
            WHEN 'BW'::text THEN NULL::text
            WHEN 'SH'::text THEN 'Yes'::text
            WHEN 'FI'::text THEN NULL::text
            ELSE 'oeps'::text
        END AS "protectedAreaShellfishObjectivesSet",
        CASE protected_area_type.code
            WHEN 'HA'::text THEN NULL::text
            WHEN 'BI'::text THEN NULL::text
            WHEN 'BW'::text THEN NULL::text
            WHEN 'SH'::text THEN 'Yes'::text
            WHEN 'FI'::text THEN NULL::text
            ELSE 'oeps'::text
        END AS "protectedAreaShellfishObjectivesMet",
    NULL::text AS "protectedAreaComment",
    wpa.hdo_id AS protectedid
   FROM ((((public.waterbody_protected_area_intersection
     JOIN public.wfd_protected_area ON ((waterbody_protected_area_intersection.wpa_id = wfd_protected_area.wpa_id)))
     JOIN public.hydro_object wpa ON ((wpa.hdo_id = wfd_protected_area.wpa_id)))
     JOIN public.hydro_object swb ON ((waterbody_protected_area_intersection.wbd_id = swb.hdo_id)))
     JOIN public.protected_area_type ON ((protected_area_type.pat_id = wfd_protected_area.protected_area_type_id)))
  WHERE ((swb.wkrv_id = 13) AND ((swb.hydro_object_type)::text = 'SurfaceWaterBody'::text) AND (protected_area_type.sw_type = true))
UNION ALL
 SELECT swb.hdo_id,
    swb.inspire_id_local_id AS "euProtectedAreaCode",
    swb.inspire_id_local_id AS "euSurfaceWaterBodyCode",
    'Article 7 Abstraction for drinking water'::text AS "protectedAreaType",
    'Within Protected Area'::text AS "protectedAreaAssociationType",
    NULL::text AS "protectedAreaHabitatsBirdsObjectivesSet",
    NULL::text AS "protectedAreaHabitatsBirdsObjectivesMet",
    'Yes'::text AS "protectedAreaDrinkinswaterObjectivesSet",
        CASE
            WHEN (swb_yearly_status.exceeds_drinkingwater IS TRUE) THEN 'No'::text
            ELSE 'Yes'::text
        END AS "protectedAreaDrinkinswaterObjectivesMet",
    NULL::text AS "protectedAreaShellfishObjectivesSet",
    NULL::text AS "protectedAreaShellfishObjectivesMet",
    NULL::text AS "protectedAreaComment",
    swb.hdo_id AS protectedid
   FROM ((public.water_body
     JOIN public.hydro_object swb ON ((swb.hdo_id = water_body.wbd_id)))
     JOIN public.swb_yearly_status ON (((swb.hdo_id = swb_yearly_status.swb_id) AND (swb_yearly_status.year_of_status = 2015))))
  WHERE ((water_body.wbd_id = swb.hdo_id) AND (water_body.is_article_7 = true) AND (swb.wkrv_id = 13) AND ((swb.hydro_object_type)::text = 'SurfaceWaterBody'::text))
  ORDER BY 3;


--
-- Name: vw_swassociatedprotectedarea_protectedareaexemption; Type: VIEW; Schema: wfd_reporting; Owner: -
--

CREATE VIEW vw_swassociatedprotectedarea_protectedareaexemption AS
 WITH exemption AS (
         SELECT objectives_exemption_type.name,
            objectives_exemption_type.description,
            objectives_exemption_type.article_nr,
            hydro_object.hdo_id,
            hydro_object.inspire_id_local_id,
            swb_chem_exemp_pollutant.chs_id
           FROM public.objectives_exemption_type,
            public.swb_exemption,
            public.hydro_object,
            public.swb_chem_exemp_pollutant
          WHERE ((swb_exemption.obex_id = objectives_exemption_type.obex_id) AND (hydro_object.hdo_id = swb_exemption.swb_id) AND (swb_chem_exemp_pollutant.swce_id = swb_exemption.swce_id))
        ), exemptions AS (
         SELECT swb.hdo_id,
            wpa.inspire_id_local_id AS "euProtectedAreaCode",
            swb.inspire_id_local_id AS "euSurfaceWaterBodyCode",
            'No exemption'::text AS "protectedAreaExemption"
           FROM (((((public.waterbody_protected_area_intersection
             LEFT JOIN public.wfd_protected_area ON ((waterbody_protected_area_intersection.wpa_id = wfd_protected_area.wpa_id)))
             LEFT JOIN public.hydro_object wpa ON ((wpa.hdo_id = wfd_protected_area.wpa_id)))
             LEFT JOIN public.hydro_object swb ON ((waterbody_protected_area_intersection.wbd_id = swb.hdo_id)))
             LEFT JOIN exemption ON ((exemption.hdo_id = swb.hdo_id)))
             LEFT JOIN public.protected_area_type ON ((protected_area_type.pat_id = wfd_protected_area.protected_area_type_id)))
          WHERE ((swb.wkrv_id = 13) AND ((swb.hydro_object_type)::text = 'SurfaceWaterBody'::text) AND (protected_area_type.sw_type = true))
        UNION ALL
         SELECT DISTINCT ON (swb.hdo_id, exemption.description) swb.hdo_id,
            swb.inspire_id_local_id AS "euProtectedAreaCode",
            swb.inspire_id_local_id AS "euSurfaceWaterBodyCode",
                CASE
                    WHEN (exemption.description IS NULL) THEN 'No exemption'::text
                    ELSE exemption.description
                END AS "protectedAreaExemption"
           FROM ((public.water_body
             LEFT JOIN public.hydro_object swb ON ((swb.hdo_id = water_body.wbd_id)))
             LEFT JOIN exemption ON ((exemption.hdo_id = swb.hdo_id)))
          WHERE ((water_body.wbd_id = swb.hdo_id) AND (water_body.is_article_7 = true) AND (swb.wkrv_id = 13) AND ((swb.hydro_object_type)::text = 'SurfaceWaterBody'::text))
  ORDER BY 1, 3
        )
 SELECT DISTINCT ON (exemptions."euProtectedAreaCode", exemptions."euSurfaceWaterBodyCode", exemptions."protectedAreaExemption") exemptions.hdo_id,
    exemptions."euProtectedAreaCode",
    exemptions."euSurfaceWaterBodyCode",
    exemptions."protectedAreaExemption"
   FROM exemptions;


--
-- Name: vw_swb_swprioritysubstance; Type: VIEW; Schema: wfd_reporting; Owner: -
--

CREATE VIEW vw_swb_swprioritysubstance AS
 WITH oordeel AS (
         SELECT DISTINCT ON (sys.sys_id, swcs.opt_id) sys.sys_id,
            sys.swb_id,
            hydro_object.inspire_id_local_id,
            swcs.opt_id,
            swcs.swcs_id,
            sge.chs_id
           FROM ((((public.swb_yearly_status sys
             JOIN public.sw_chemical_substance_status swcs ON ((swcs.sys_id = sys.sys_id)))
             JOIN public.observed_property_type ON ((observed_property_type.opt_id = swcs.opt_id)))
             JOIN public.substance_group_element sge ON ((sge.ssge_id = observed_property_type.substance_group_id)))
             JOIN public.hydro_object ON ((hydro_object.hdo_id = sys.swb_id)))
          WHERE ((sge.chs_id IS NOT NULL) AND (swcs.eumg_id = 3) AND (sys.year_of_status = 2015) AND (hydro_object.wkrv_id = 13))
          ORDER BY sys.sys_id, swcs.opt_id, swcs.wbpm_id DESC
        ), oordeel2009 AS (
         SELECT DISTINCT ON (sys.sys_id, swcs.opt_id) sys.sys_id,
            sys.swb_id,
            hydro_object.inspire_id_local_id,
            swcs.opt_id,
            swcs.swcs_id,
            sge.chs_id
           FROM ((((public.swb_yearly_status sys
             JOIN public.sw_chemical_substance_status swcs ON ((swcs.sys_id = sys.sys_id)))
             JOIN public.observed_property_type ON ((observed_property_type.opt_id = swcs.opt_id)))
             JOIN public.substance_group_element sge ON ((sge.ssge_id = observed_property_type.substance_group_id)))
             JOIN public.hydro_object ON ((hydro_object.hdo_id = sys.swb_id)))
          WHERE ((sge.chs_id IS NOT NULL) AND (sys.year_of_status = 2009) AND (hydro_object.wkrv_id = 2))
          ORDER BY sys.sys_id, swcs.opt_id, swcs.wbpm_id DESC, swcs.eumg_id DESC
        ), kental AS (
         SELECT observation.observed_property_type AS opt_id,
            sys.sys_id,
            sys.swb_id,
            observation.value_processing_method_id
           FROM (((((public.swb_yearly_status sys
             JOIN public.sw_testing_conclusion tc ON ((tc.sys_id = sys.sys_id)))
             JOIN public.observation ON ((tc.stcc_id = observation.obs_id)))
             JOIN public.hydro_object ON ((hydro_object.hdo_id = sys.swb_id)))
             JOIN public.observed_property_type ON ((observed_property_type.opt_id = observation.observed_property_type)))
             JOIN public.substance_group_element sge ON ((sge.ssge_id = observed_property_type.substance_group_id)))
          WHERE ((sge.chs_id IS NOT NULL) AND (tc.eumg_id = 3) AND (hydro_object.wkrv_id = 13) AND (sys.year_of_status = 2015))
        ), stofgroep AS (
         SELECT substance_group_element.chs_id,
            substance_group_element.ssge_id,
                CASE substance_group_element.ssge_id
                    WHEN 3155 THEN 'STOFOV'::text
                    WHEN 3149 THEN 'STOFPR_UBQN'::text
                    WHEN 3150 THEN 'STOFPR_UBQJ'::text
                    WHEN 2907 THEN 'CHEMT'::text
                    WHEN 3148 THEN 'STOFPR_34-45'::text
                    ELSE NULL::text
                END AS categorie
           FROM public.substance_group_element
          WHERE (substance_group_element.ssge_id = ANY (ARRAY[3155, 3150, 3149, 3148, 2907]))
        ), eu_stoffenlijst AS (
         SELECT chemische_stof_type.chs_id,
            chemische_stof_type.cas_nr,
            chemische_stof_type.naam,
            chemische_stof_type.code,
            chemische_stof_type.d_begin,
            chemische_stof_type.d_eind,
            chemische_stof_type.last_changed_date,
            chemische_stof_type.d_status,
            chemische_stof_type.id,
            eu_stoffenlijst_1.domeinnaam,
            eu_stoffenlijst_1.value,
            eu_stoffenlijst_1.grootheidcode,
            eu_stoffenlijst_1.parametercode,
            eu_stoffenlijst_1."swFailingRBSPOther"
           FROM public.chemische_stof_type,
            wfd_reporting.eu_stoffenlijst eu_stoffenlijst_1
          WHERE (((eu_stoffenlijst_1.parametercode)::text = (chemische_stof_type.code)::text) AND ((eu_stoffenlijst_1.domeinnaam)::text = 'PS_Enum'::text))
        )
 SELECT ((oordeel.swb_id)::text || (chs.chs_id)::text) AS "sWPrioritySubstanceID",
    oordeel.inspire_id_local_id AS "euSurfaceWaterBodyCode",
    eu_stoffenlijst.value AS "swFailingRBSP",
        CASE
            WHEN (oordeel.swcs_id = 2) THEN true
            ELSE false
        END AS "swPrioritySubstanceCausingFailure",
        CASE
            WHEN (kental.value_processing_method_id = 26563) THEN 'MAC EQS'::text
            ELSE 'AA EQS'::text
        END AS "swPrioritySubstanceExceedanceType",
        CASE
            WHEN ((oordeel.swcs_id = 1) AND (oordeel2009.swcs_id = 2)) THEN true
            ELSE false
        END AS "swPrioritySubstanceImprovingChemicalStatus",
        CASE
            WHEN ((wsc.scm_id = 4) AND (oordeel.swcs_id = 2) AND (oordeel.chs_id = ANY (ARRAY[516, 2609, 1015, 1411, 1230, 1242, 556, 557, 575, 265, 1101]))) THEN true
            ELSE false
        END AS "swPrioritySubstanceEffectStatusNewThresholds",
    NULL::text AS "swPrioritySubstanceExceedanceMixingZone"
   FROM ((((((((((oordeel
     LEFT JOIN stofgroep ON ((stofgroep.chs_id = oordeel.chs_id)))
     LEFT JOIN public.chemische_stof_type chs ON ((chs.chs_id = oordeel.chs_id)))
     LEFT JOIN public.water_body ON ((oordeel.swb_id = water_body.wbd_id)))
     LEFT JOIN public.hydro_object rb ON ((rb.hdo_id = water_body.rbd_id)))
     LEFT JOIN public.related_hydro_object rho ON (((rho.from_hdo = oordeel.swb_id) AND (rho.rrt_id = 9))))
     LEFT JOIN public.wb_status_change_motivation wsc ON (((wsc.wbd_id = oordeel.swb_id) AND (wsc.opt_id = oordeel.opt_id) AND (wsc.year_status = 2015) AND (wsc.year_initial = 2009))))
     LEFT JOIN public.hydro_object hdo2009 ON ((rho.to_hdo = hdo2009.hdo_id)))
     LEFT JOIN oordeel2009 ON (((oordeel2009.swb_id = hdo2009.hdo_id) AND (oordeel2009.opt_id = oordeel.opt_id) AND (oordeel2009.chs_id = oordeel.chs_id))))
     LEFT JOIN kental ON (((oordeel.swb_id = kental.swb_id) AND (oordeel.opt_id = kental.opt_id))))
     LEFT JOIN eu_stoffenlijst ON (((chs.code)::text = (eu_stoffenlijst.parametercode)::text)))
  WHERE ((stofgroep.categorie = 'CHEMT'::text) AND ((oordeel.swcs_id = 2) OR ((oordeel2009.swcs_id = 2) AND (oordeel.swcs_id = 1))) AND (eu_stoffenlijst.value IS NOT NULL))
  ORDER BY rb.inspire_id_local_id, oordeel.inspire_id_local_id, eu_stoffenlijst.value;


--
-- Name: vw_swb_swprioritysubstance2; Type: VIEW; Schema: wfd_reporting; Owner: -
--

CREATE VIEW vw_swb_swprioritysubstance2 AS
 WITH oordeel AS (
         SELECT DISTINCT ON (sys.sys_id, swcs.opt_id) sys.sys_id,
            sys.swb_id,
            hydro_object.inspire_id_local_id,
            swcs.opt_id,
            swcs.swcs_id,
            sge.chs_id
           FROM ((((public.swb_yearly_status sys
             JOIN public.sw_chemical_substance_status swcs ON ((swcs.sys_id = sys.sys_id)))
             JOIN public.observed_property_type ON ((observed_property_type.opt_id = swcs.opt_id)))
             JOIN public.substance_group_element sge ON ((sge.ssge_id = observed_property_type.substance_group_id)))
             JOIN public.hydro_object ON ((hydro_object.hdo_id = sys.swb_id)))
          WHERE ((sge.chs_id IS NOT NULL) AND (swcs.eumg_id = 3) AND (sys.year_of_status = 2015) AND (hydro_object.wkrv_id = 13))
          ORDER BY sys.sys_id, swcs.opt_id, swcs.wbpm_id DESC
        ), oordeel2009 AS (
         SELECT DISTINCT ON (sys.sys_id, swcs.opt_id) sys.sys_id,
            sys.swb_id,
            hydro_object.inspire_id_local_id,
            swcs.opt_id,
            swcs.swcs_id,
            sge.chs_id
           FROM ((((public.swb_yearly_status sys
             JOIN public.sw_chemical_substance_status swcs ON ((swcs.sys_id = sys.sys_id)))
             JOIN public.observed_property_type ON ((observed_property_type.opt_id = swcs.opt_id)))
             JOIN public.substance_group_element sge ON ((sge.ssge_id = observed_property_type.substance_group_id)))
             JOIN public.hydro_object ON ((hydro_object.hdo_id = sys.swb_id)))
          WHERE ((sge.chs_id IS NOT NULL) AND (sys.year_of_status = 2009) AND (hydro_object.wkrv_id = 2))
          ORDER BY sys.sys_id, swcs.opt_id, swcs.wbpm_id DESC, swcs.eumg_id DESC
        ), kental AS (
         SELECT observation.observed_property_type AS opt_id,
            sys.sys_id,
            sys.swb_id,
            observation.value_processing_method_id
           FROM (((((public.swb_yearly_status sys
             JOIN public.sw_testing_conclusion tc ON ((tc.sys_id = sys.sys_id)))
             JOIN public.observation ON ((tc.stcc_id = observation.obs_id)))
             JOIN public.hydro_object ON ((hydro_object.hdo_id = sys.swb_id)))
             JOIN public.observed_property_type ON ((observed_property_type.opt_id = observation.observed_property_type)))
             JOIN public.substance_group_element sge ON ((sge.ssge_id = observed_property_type.substance_group_id)))
          WHERE ((sge.chs_id IS NOT NULL) AND (tc.eumg_id = 3) AND (hydro_object.wkrv_id = 13) AND (sys.year_of_status = 2015))
        ), stofgroep AS (
         SELECT substance_group_element.chs_id,
            substance_group_element.ssge_id,
                CASE substance_group_element.ssge_id
                    WHEN 3155 THEN 'STOFOV'::text
                    WHEN 3149 THEN 'STOFPR_UBQN'::text
                    WHEN 3150 THEN 'STOFPR_UBQJ'::text
                    WHEN 2907 THEN 'CHEMT'::text
                    WHEN 3148 THEN 'STOFPR_34-45'::text
                    ELSE NULL::text
                END AS categorie
           FROM public.substance_group_element
          WHERE (substance_group_element.ssge_id = ANY (ARRAY[3155, 3150, 3149, 3148, 2907]))
        )
 SELECT ((oordeel.swb_id)::text || (chs.chs_id)::text) AS "sWPrioritySubstanceID",
    oordeel.inspire_id_local_id AS "euSurfaceWaterBodyCode",
    chs.cas_nr AS "swFailingRBSP_Casnr",
    chs.code AS "swFailingRBSP_code",
    chs.naam AS "swFailingRBSP_naam",
        CASE
            WHEN (oordeel.swcs_id = 2) THEN true
            ELSE false
        END AS "swPrioritySubstanceCausingFailure",
        CASE
            WHEN (kental.value_processing_method_id = 26563) THEN 'MAC EQS'::text
            ELSE 'AA EQS'::text
        END AS "swPrioritySubstanceExceedanceType",
        CASE
            WHEN ((oordeel.swcs_id = 1) AND (oordeel2009.swcs_id = 2)) THEN true
            ELSE false
        END AS "swPrioritySubstanceImprovingChemicalStatus",
        CASE
            WHEN ((wsc.scm_id = 4) AND (oordeel.swcs_id = 2) AND (oordeel.chs_id = ANY (ARRAY[516, 2609, 1015, 1411, 1230, 1242, 556, 557, 575, 265, 1101]))) THEN true
            ELSE false
        END AS "swPrioritySubstanceEffectStatusNewThresholds",
    NULL::text AS "swPrioritySubstanceExceedanceMixingZone"
   FROM (((((((((oordeel
     LEFT JOIN stofgroep ON ((stofgroep.chs_id = oordeel.chs_id)))
     LEFT JOIN public.chemische_stof_type chs ON ((chs.chs_id = oordeel.chs_id)))
     LEFT JOIN public.water_body ON ((oordeel.swb_id = water_body.wbd_id)))
     LEFT JOIN public.hydro_object rb ON ((rb.hdo_id = water_body.rbd_id)))
     LEFT JOIN public.related_hydro_object rho ON (((rho.from_hdo = oordeel.swb_id) AND (rho.rrt_id = 9))))
     LEFT JOIN public.wb_status_change_motivation wsc ON (((wsc.wbd_id = oordeel.swb_id) AND (wsc.opt_id = oordeel.opt_id) AND (wsc.year_status = 2015) AND (wsc.year_initial = 2009))))
     LEFT JOIN public.hydro_object hdo2009 ON ((rho.to_hdo = hdo2009.hdo_id)))
     LEFT JOIN oordeel2009 ON (((oordeel2009.swb_id = hdo2009.hdo_id) AND (oordeel2009.opt_id = oordeel.opt_id) AND (oordeel2009.chs_id = oordeel.chs_id))))
     LEFT JOIN kental ON (((oordeel.swb_id = kental.swb_id) AND (oordeel.opt_id = kental.opt_id))))
  WHERE ((stofgroep.categorie = 'CHEMT'::text) AND ((oordeel.swcs_id = 2) OR ((oordeel2009.swcs_id = 2) AND (oordeel.swcs_id = 1))))
  ORDER BY rb.inspire_id_local_id, oordeel.inspire_id_local_id, chs.code;


--
-- Name: vw_swchemicalexemptionpressure; Type: VIEW; Schema: wfd_reporting; Owner: -
--

CREATE VIEW vw_swchemicalexemptionpressure AS
 WITH oordeel AS (
         SELECT DISTINCT ON (sys.sys_id, swcs.opt_id) sys.sys_id,
            sys.swb_id,
            hydro_object.inspire_id_local_id,
            swcs.opt_id,
            swcs.swcs_id,
            sge.chs_id,
            hydro_object.wkrv_id,
            hydro_object.hydro_object_type
           FROM ((((public.swb_yearly_status sys
             JOIN public.sw_chemical_substance_status swcs ON ((swcs.sys_id = sys.sys_id)))
             JOIN public.observed_property_type ON ((observed_property_type.opt_id = swcs.opt_id)))
             JOIN public.substance_group_element sge ON ((sge.ssge_id = observed_property_type.substance_group_id)))
             JOIN public.hydro_object ON ((hydro_object.hdo_id = sys.swb_id)))
          WHERE ((sge.chs_id IS NOT NULL) AND (swcs.eumg_id = 3) AND (sys.year_of_status = 2015) AND (hydro_object.wkrv_id = 13))
          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 'STOFOV'::text
                    WHEN 3149 THEN 'STOFPR_UBQN'::text
                    WHEN 3150 THEN 'STOFPR_UBQJ'::text
                    WHEN 2907 THEN 'CHEMT'::text
                    WHEN 3148 THEN 'STOFPR_34-45'::text
                    ELSE NULL::text
                END AS categorie
           FROM public.substance_group_element
          WHERE (substance_group_element.ssge_id = ANY (ARRAY[3155, 3150, 3149, 3148, 2907]))
        ), exemption AS (
         SELECT DISTINCT ON (hydro_object.hdo_id, objectives_exemption_type.obex_id, swb_chem_exemp_pollutant.chs_id) objectives_exemption_type.name,
            objectives_exemption_type.description,
            objectives_exemption_type.article_nr,
            hydro_object.hdo_id,
            hydro_object.inspire_id_local_id,
            swb_chem_exemp_pollutant.chs_id,
            objectives_exemption_type.obex_id
           FROM (((public.swb_exemption
             JOIN public.hydro_object ON ((hydro_object.hdo_id = swb_exemption.swb_id)))
             JOIN public.objectives_exemption_type ON ((swb_exemption.obex_id = objectives_exemption_type.obex_id)))
             JOIN public.swb_chem_exemp_pollutant ON ((swb_chem_exemp_pollutant.swce_id = swb_exemption.swce_id)))
          ORDER BY hydro_object.hdo_id, objectives_exemption_type.obex_id, swb_chem_exemp_pollutant.chs_id
        ), pressures AS (
         SELECT DISTINCT ON (hydro_object.hdo_id, spe.eu_xsd) hydro_object.hdo_id AS db_id,
            hydro_object.inspire_id_local_id AS "euSurfaceWaterBodyCode",
                CASE
                    WHEN (spe.eu_xsd IS NULL) THEN 'No significant pressure'::text
                    ELSE spe.eu_xsd
                END AS "swSignificantPressureType"
           FROM ((public.hydro_object
             LEFT JOIN public.swb_pressure ON ((hydro_object.hdo_id = swb_pressure.swb_id)))
             LEFT JOIN significant_pressure_enum spe ON ((spe.sw_p_id = swb_pressure.sprs_id)))
          WHERE ((swb_pressure.is_significant = true) AND (hydro_object.wkrv_id = 13))
          ORDER BY hydro_object.hdo_id, spe.eu_xsd
        ), bel_aant AS (
         SELECT hydro_object.hdo_id AS db_id,
            count(spe.eu_xsd) AS aant
           FROM ((public.hydro_object
             LEFT JOIN public.swb_pressure ON ((hydro_object.hdo_id = swb_pressure.swb_id)))
             LEFT JOIN significant_pressure_enum spe ON (((spe.sw_p_id = swb_pressure.sprs_id) AND (swb_pressure.is_significant = true))))
          GROUP BY hydro_object.hdo_id, hydro_object.wkrv_id, hydro_object.hydro_object_type
         HAVING ((hydro_object.wkrv_id = 13) AND ((hydro_object.hydro_object_type)::text = 'SurfaceWaterBody'::text))
        )
 SELECT DISTINCT ON (oordeel.swb_id, exemption.obex_id, chs.chs_id, pressures."swSignificantPressureType")
        CASE
            WHEN (exemption.obex_id IS NULL) THEN (((oordeel.swb_id)::text || (chs.chs_id)::text) || '0'::text)
            ELSE (((oordeel.swb_id)::text || (chs.chs_id)::text) || exemption.obex_id)
        END AS "sWChemicalExemptionTypeID",
    pressures."swSignificantPressureType" AS "swChemicalExemptionPressure"
   FROM ((((((public.water_body
     JOIN oordeel ON ((water_body.wbd_id = oordeel.swb_id)))
     JOIN stofgroep ON ((stofgroep.chs_id = oordeel.chs_id)))
     JOIN public.chemische_stof_type chs ON ((chs.chs_id = oordeel.chs_id)))
     LEFT JOIN exemption ON (((exemption.hdo_id = oordeel.swb_id) AND (exemption.chs_id = oordeel.chs_id))))
     LEFT JOIN pressures ON ((oordeel.swb_id = pressures.db_id)))
     LEFT JOIN bel_aant ON ((bel_aant.db_id = oordeel.swb_id)))
  WHERE ((stofgroep.categorie = 'CHEMT'::text) AND (oordeel.swcs_id = 2) AND (water_body.wbd_id = oordeel.swb_id) AND (oordeel.wkrv_id = 13) AND ((oordeel.hydro_object_type)::text = 'SurfaceWaterBody'::text) AND (exemption.description IS NOT NULL) AND (((bel_aant.aant = 0) AND (pressures."swSignificantPressureType" = 'No significant pressure'::text)) OR ((bel_aant.aant > 0) AND (pressures."swSignificantPressureType" <> 'No significant pressure'::text))))
  ORDER BY oordeel.swb_id, exemption.obex_id, chs.chs_id, pressures."swSignificantPressureType";


--
-- Name: vw_swchemicalexemptiontype; Type: VIEW; Schema: wfd_reporting; Owner: -
--

CREATE VIEW vw_swchemicalexemptiontype AS
 WITH oordeel AS (
         SELECT DISTINCT ON (sys.sys_id, swcs.opt_id) sys.sys_id,
            sys.swb_id,
            hydro_object.inspire_id_local_id,
            swcs.opt_id,
            swcs.swcs_id,
            sge.chs_id,
            hydro_object.wkrv_id,
            hydro_object.hydro_object_type
           FROM ((((public.swb_yearly_status sys
             JOIN public.sw_chemical_substance_status swcs ON ((swcs.sys_id = sys.sys_id)))
             JOIN public.observed_property_type ON ((observed_property_type.opt_id = swcs.opt_id)))
             JOIN public.substance_group_element sge ON ((sge.ssge_id = observed_property_type.substance_group_id)))
             JOIN public.hydro_object ON ((hydro_object.hdo_id = sys.swb_id)))
          WHERE ((sge.chs_id IS NOT NULL) AND (swcs.eumg_id = 3) AND (sys.year_of_status = 2015) AND (hydro_object.wkrv_id = 13) AND (swcs.swcs_id = 2))
          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 'STOFOV'::text
                    WHEN 3149 THEN 'STOFPR_UBQN'::text
                    WHEN 3150 THEN 'STOFPR_UBQJ'::text
                    WHEN 2907 THEN 'CHEMT'::text
                    WHEN 3148 THEN 'STOFPR_34-45'::text
                    ELSE NULL::text
                END AS categorie
           FROM public.substance_group_element
          WHERE (substance_group_element.ssge_id = ANY (ARRAY[3155, 3150, 3149, 3148, 2907]))
        ), exemption AS (
         SELECT objectives_exemption_type.name,
            hydro_object.inspire_id_local_id,
            objectives_exemption_type.description,
            objectives_exemption_type.article_nr,
            hydro_object.hdo_id,
            hydro_object.inspire_id_local_id,
            NULL::integer AS chs_id,
            swb_ecol_exemp_qe.opt_id,
            objectives_exemption_type.obex_id
           FROM (((public.swb_exemption
             JOIN public.hydro_object ON ((hydro_object.hdo_id = swb_exemption.swb_id)))
             JOIN public.objectives_exemption_type ON ((swb_exemption.obex_id = objectives_exemption_type.obex_id)))
             JOIN public.swb_ecol_exemp_qe ON ((swb_ecol_exemp_qe.swce_id = swb_exemption.swce_id)))
          WHERE ((hydro_object.wkrv_id = 13) AND (swb_ecol_exemp_qe.opt_id = ANY (ARRAY[4520, 4477, 5892, 5893, 5891])))
          ORDER BY objectives_exemption_type.name, swb_ecol_exemp_qe.opt_id
        ), exemption_s AS (
         SELECT objectives_exemption_type.name,
            hydro_object.inspire_id_local_id,
            objectives_exemption_type.description,
            objectives_exemption_type.article_nr,
            hydro_object.hdo_id,
            hydro_object.inspire_id_local_id,
            swb_chem_exemp_pollutant.chs_id,
            objectives_exemption_type.obex_id
           FROM (((public.swb_exemption
             JOIN public.hydro_object ON ((hydro_object.hdo_id = swb_exemption.swb_id)))
             JOIN public.objectives_exemption_type ON ((swb_exemption.obex_id = objectives_exemption_type.obex_id)))
             JOIN public.swb_chem_exemp_pollutant ON ((swb_chem_exemp_pollutant.swce_id = swb_exemption.swce_id)))
          WHERE (hydro_object.wkrv_id = 13)
          ORDER BY objectives_exemption_type.name, objectives_exemption_type.obex_id
        ), exemption_totaal AS (
         SELECT oordeel_1.swb_id,
            oordeel_1.chs_id,
            exemption.obex_id,
            oordeel_1.inspire_id_local_id,
            exemption.description
           FROM ((oordeel oordeel_1
             JOIN stofgroep stofgroep_1 ON ((stofgroep_1.chs_id = oordeel_1.chs_id)))
             JOIN exemption exemption(name, inspire_id_local_id, description, article_nr, hdo_id, inspire_id_local_id_1, chs_id, opt_id, obex_id) ON ((oordeel_1.swb_id = exemption.hdo_id)))
          WHERE (stofgroep_1.categorie = 'CHEMT'::text)
        UNION
         SELECT oordeel_1.swb_id,
            oordeel_1.chs_id,
            exemption_s.obex_id,
            oordeel_1.inspire_id_local_id,
            exemption_s.description
           FROM ((oordeel oordeel_1
             JOIN stofgroep stofgroep_1 ON ((stofgroep_1.chs_id = oordeel_1.chs_id)))
             JOIN exemption_s exemption_s(name, inspire_id_local_id, description, article_nr, hdo_id, inspire_id_local_id_1, chs_id, obex_id) ON (((oordeel_1.swb_id = exemption_s.hdo_id) AND (exemption_s.chs_id = oordeel_1.chs_id))))
          WHERE (stofgroep_1.categorie = 'CHEMT'::text)
  ORDER BY 4, 2, 3
        )
 SELECT ((oordeel.swb_id)::text || (oordeel.chs_id)::text) AS "sWPrioritySubstanceID",
        CASE
            WHEN (ext.obex_id IS NULL) THEN (((oordeel.swb_id)::text || (oordeel.chs_id)::text) || '0'::text)
            ELSE (((oordeel.swb_id)::text || (oordeel.chs_id)::text) || ext.obex_id)
        END AS "sWChemicalExemptionTypeID",
    oordeel.inspire_id_local_id AS "euSurfaceWaterBodyCode",
        CASE
            WHEN (ext.description IS NULL) THEN 'No exemption'::text
            ELSE ext.description
        END AS "swChemicalExemptionType"
   FROM ((oordeel
     JOIN stofgroep ON ((stofgroep.chs_id = oordeel.chs_id)))
     LEFT JOIN exemption_totaal ext ON (((oordeel.swb_id = ext.swb_id) AND (ext.chs_id = oordeel.chs_id))))
  WHERE (stofgroep.categorie = 'CHEMT'::text)
  ORDER BY oordeel.inspire_id_local_id, ((oordeel.swb_id)::text || (oordeel.chs_id)::text);


--
-- Name: vw_swecologicalexemptiontype; Type: VIEW; Schema: wfd_reporting; Owner: -
--

CREATE VIEW vw_swecologicalexemptiontype AS
 WITH swb_oordeel AS (
         SELECT DISTINCT ON (hdo_swb.hdo_id, sw_ecological_status.opt_id) hdo_swb.hdo_id AS swb_id,
            hdo_swb.inspire_id_local_id,
            swb_yearly_status.year_of_status AS jaar,
            sw_ecological_status.opt_id,
            classification_type.description AS oordeel,
            waarde_bepalings_methode_type.code AS wbpm
           FROM ((((public.swb_yearly_status
             LEFT JOIN public.hydro_object hdo_swb ON ((hdo_swb.hdo_id = swb_yearly_status.swb_id)))
             JOIN public.sw_ecological_status ON ((sw_ecological_status.sys_id = swb_yearly_status.sys_id)))
             LEFT JOIN public.classification_type ON ((sw_ecological_status.swes_id = classification_type.cls_id)))
             LEFT JOIN public.waarde_bepalings_methode_type ON ((waarde_bepalings_methode_type.wbpm_id = sw_ecological_status.wbpm_id)))
          WHERE ((hdo_swb.wkrv_id = 13) AND (swb_yearly_status.year_of_status = 2015) AND ((classification_type.description)::text <> 'goed'::text) AND (sw_ecological_status.opt_id = 4479))
          ORDER BY hdo_swb.hdo_id, sw_ecological_status.opt_id, waarde_bepalings_methode_type.code DESC
        )
 SELECT DISTINCT ON (swb_oordeel.swb_id, gwce.obex_id)
        CASE
            WHEN (gwce.obex_id IS NULL) THEN ((swb_oordeel.swb_id)::text || '0'::text)
            ELSE ((swb_oordeel.swb_id)::text || (gwce.obex_id)::text)
        END AS "sWEcologicalExemptionTypeID",
    swb_oordeel.inspire_id_local_id AS "euSurfaceWaterBodyCode",
        CASE
            WHEN (objectives_exemption_type.description IS NULL) THEN 'No exemption'::text
            ELSE objectives_exemption_type.description
        END AS "swEcologicalExemptionType"
   FROM ((swb_oordeel
     LEFT JOIN public.swb_exemption gwce ON ((gwce.swb_id = swb_oordeel.swb_id)))
     LEFT JOIN public.objectives_exemption_type ON ((objectives_exemption_type.obex_id = gwce.obex_id)))
  ORDER BY swb_oordeel.swb_id, gwce.obex_id;


--
-- Name: vw_swecologicalexemptiontype_swecologicalexemptionpressure; Type: VIEW; Schema: wfd_reporting; Owner: -
--

CREATE VIEW vw_swecologicalexemptiontype_swecologicalexemptionpressure AS
 WITH swb_oordeel AS (
         SELECT DISTINCT ON (hdo_swb.hdo_id, sw_ecological_status.opt_id) hdo_swb.hdo_id AS swb_id,
            hdo_swb.inspire_id_local_id,
            swb_yearly_status.year_of_status AS jaar,
            sw_ecological_status.opt_id,
            classification_type.description AS oordeel,
            waarde_bepalings_methode_type.code AS wbpm
           FROM ((((public.swb_yearly_status
             LEFT JOIN public.hydro_object hdo_swb ON ((hdo_swb.hdo_id = swb_yearly_status.swb_id)))
             JOIN public.sw_ecological_status ON ((sw_ecological_status.sys_id = swb_yearly_status.sys_id)))
             LEFT JOIN public.classification_type ON ((sw_ecological_status.swes_id = classification_type.cls_id)))
             LEFT JOIN public.waarde_bepalings_methode_type ON ((waarde_bepalings_methode_type.wbpm_id = sw_ecological_status.wbpm_id)))
          WHERE ((hdo_swb.wkrv_id = 13) AND (swb_yearly_status.year_of_status = 2015) AND (sw_ecological_status.opt_id = 4479))
          ORDER BY hdo_swb.hdo_id, sw_ecological_status.opt_id, waarde_bepalings_methode_type.code DESC
        ), pressures AS (
         SELECT DISTINCT ON (hydro_object.hdo_id, spe.eu_xsd) hydro_object.hdo_id AS db_id,
            swb_pressure.sprs_id,
            hydro_object.inspire_id_local_id AS "euSurfaceWaterBodyCode",
                CASE
                    WHEN (spe.eu_xsd IS NULL) THEN 'No significant pressure'::text
                    ELSE spe.eu_xsd
                END AS "swSignificantPressureType"
           FROM ((public.hydro_object
             LEFT JOIN public.swb_pressure ON ((hydro_object.hdo_id = swb_pressure.swb_id)))
             LEFT JOIN significant_pressure_enum spe ON ((spe.sw_p_id = swb_pressure.sprs_id)))
          WHERE ((swb_pressure.is_significant = true) AND (hydro_object.wkrv_id = 13))
          ORDER BY hydro_object.hdo_id, spe.eu_xsd
        )
 SELECT DISTINCT ON (swb_oordeel.swb_id, pressures.sprs_id, gwce.obex_id)
        CASE
            WHEN (gwce.obex_id IS NULL) THEN ((swb_oordeel.swb_id)::text || '0'::text)
            ELSE ((swb_oordeel.swb_id)::text || (gwce.obex_id)::text)
        END AS "sWEcologicalExemptionTypeID",
    pressures."euSurfaceWaterBodyCode",
    pressures."swSignificantPressureType" AS "swEcologicalExemptionPressure"
   FROM (((swb_oordeel
     LEFT JOIN public.swb_exemption gwce ON ((gwce.swb_id = swb_oordeel.swb_id)))
     LEFT JOIN pressures ON (((swb_oordeel.swb_id = pressures.db_id) AND ((swb_oordeel.oordeel)::text <> 'goed'::text) AND (pressures."swSignificantPressureType" <> 'No significant pressure'::text))))
     LEFT JOIN public.objectives_exemption_type ON ((objectives_exemption_type.obex_id = gwce.obex_id)))
  ORDER BY swb_oordeel.swb_id, pressures.sprs_id, gwce.obex_id;


--
-- Name: vw_swecologicalmonitoring; Type: VIEW; Schema: wfd_reporting; Owner: -
--

CREATE VIEW vw_swecologicalmonitoring AS
 SELECT DISTINCT ON (mpn.mpnident, mpn.parameter) eu_stoffenlijst.value AS "qeCode",
    (eu_stoffenlijst."swFailingRBSPOther")::text AS "qeDescription",
    'Water'::text AS "chemicalMatrix",
        CASE
            WHEN ((mpn.mpntype)::text = 'gw'::text) THEN 'Both'::text
            ELSE 'Status'::text
        END AS "chemicalPurpose",
    mpn.monfreq AS "qeFrequency",
    mpn.moncyclus AS "qeCycle",
    mpn.tot AS "qeLastMonitored",
        CASE
            WHEN ("substring"((mpn.mpnident)::text, 1, 2) <> 'NL'::text) THEN ('NL_'::text || (mpn.mpnident)::text)
            ELSE (mpn.mpnident)::text
        END AS "euMonitoringSiteCode",
    "left"((mpn.sgb)::text, 4) AS sgb
   FROM (eu_state_of_environment.monprog_2015 mpn
     JOIN eu_stoffenlijst ON ((((mpn.parameter)::text = (eu_stoffenlijst.parametercode)::text) AND ((eu_stoffenlijst.domeinnaam)::text = ANY (ARRAY[('SupportingQE_Enum'::character varying)::text, ('BQE_Enum'::character varying)::text, ('PhysChemQE_Enum'::character varying)::text])))))
  WHERE ((mpn.purpose)::text = 'ecologie'::text)
  ORDER BY mpn.mpnident, mpn.parameter, mpn.purpose, mpn.monsoort DESC;


--
-- Name: vw_swexemptions; Type: VIEW; Schema: wfd_reporting; Owner: -
--

CREATE VIEW vw_swexemptions AS
 SELECT DISTINCT ON (("left"((hdo_rbd2.inspire_id_local_id)::text, 4)))
        CASE
            WHEN (rbd.international_rbd IS NULL) THEN hdo_rbd.hdo_id
            ELSE rbd.international_rbd
        END AS "sWExemptionsID",
    "left"((hdo_rbd2.inspire_id_local_id)::text, 4) AS "euRBDCode",
        CASE
            WHEN (gwce.obex_id = 2) THEN 'Yes'::text
            ELSE 'No'::text
        END AS "swDisproportionateCost",
    'No'::text AS "swDisproportionateCostOtherEULegislation",
    'No'::text AS "swExemptionsTransboundary"
   FROM (((((public.hydro_object hdo_rbd2
     JOIN public.objectives_exemption_type ON ((1 = 1)))
     LEFT JOIN public.swb_exemption gwce ON ((objectives_exemption_type.obex_id = gwce.obex_id)))
     LEFT JOIN public.water_body ON ((water_body.wbd_id = gwce.swb_id)))
     LEFT JOIN public.river_basin_disrict rbd ON ((rbd.rbd_id = water_body.rbd_id)))
     LEFT JOIN public.hydro_object hdo_rbd ON ((rbd.rbd_id = hdo_rbd.hdo_id)))
  WHERE ((hdo_rbd2.wkrv_id = 13) AND ((hdo_rbd2.hydro_object_type)::text = 'RiverBasinDistrict'::text) AND ((hdo_rbd2.inspire_id_local_id)::text ~~ 'NL%'::text) AND (((substr(objectives_exemption_type.description, 8, 4) = '4(4)'::text) AND (gwce.obex_id = 2)) OR (substr(objectives_exemption_type.description, 8, 4) = ANY (ARRAY['4(5)'::text, '4(6)'::text, '4(7)'::text]))))
  ORDER BY ("left"((hdo_rbd2.inspire_id_local_id)::text, 4));


--
-- Name: vw_swexemptions_swexemption44driver; Type: VIEW; Schema: wfd_reporting; Owner: -
--

CREATE VIEW vw_swexemptions_swexemption44driver AS
 WITH swb_oordeel AS (
         SELECT DISTINCT ON (hdo_swb.hdo_id, sw_ecological_status.opt_id) hdo_swb.hdo_id AS swb_id,
            swb_yearly_status.year_of_status AS jaar,
            sw_ecological_status.opt_id,
            classification_type.description AS oordeel,
            waarde_bepalings_methode_type.code AS wbpm
           FROM ((((public.swb_yearly_status
             LEFT JOIN public.hydro_object hdo_swb ON ((hdo_swb.hdo_id = swb_yearly_status.swb_id)))
             JOIN public.sw_ecological_status ON ((sw_ecological_status.sys_id = swb_yearly_status.sys_id)))
             LEFT JOIN public.classification_type ON ((sw_ecological_status.swes_id = classification_type.cls_id)))
             LEFT JOIN public.waarde_bepalings_methode_type ON ((waarde_bepalings_methode_type.wbpm_id = sw_ecological_status.wbpm_id)))
          WHERE ((hdo_swb.wkrv_id = 13) AND (swb_yearly_status.year_of_status = 2015) AND ((classification_type.description)::text <> 'goed'::text))
        UNION ALL
         SELECT DISTINCT ON (hdo_swb.hdo_id, sw_chemical_substance_status.opt_id) hdo_swb.hdo_id AS swb_id,
            swb_yearly_status.year_of_status AS jaar,
            sw_chemical_substance_status.opt_id,
            classification_type.description AS oordeel,
            waarde_bepalings_methode_type.code AS wbpm
           FROM ((((public.swb_yearly_status
             LEFT JOIN public.hydro_object hdo_swb ON ((hdo_swb.hdo_id = swb_yearly_status.swb_id)))
             JOIN public.sw_chemical_substance_status ON ((sw_chemical_substance_status.sys_id = swb_yearly_status.sys_id)))
             LEFT JOIN public.classification_type ON ((sw_chemical_substance_status.swcs_id = classification_type.cls_id)))
             LEFT JOIN public.waarde_bepalings_methode_type ON ((waarde_bepalings_methode_type.wbpm_id = sw_chemical_substance_status.wbpm_id)))
          WHERE ((hdo_swb.wkrv_id = 13) AND (swb_yearly_status.year_of_status = 2015) AND ((classification_type.description)::text = 'voldoet niet'::text))
  ORDER BY 1, 3, 4 DESC
        ), swb_oordeel_i AS (
         SELECT DISTINCT ON (swb_oordeel_1.swb_id) swb_oordeel_1.swb_id,
            swb_oordeel_1.opt_id,
            swb_oordeel_1.jaar,
            swb_oordeel_1.oordeel,
            swb_oordeel_1.wbpm
           FROM swb_oordeel swb_oordeel_1
          ORDER BY swb_oordeel_1.swb_id, swb_oordeel_1.oordeel DESC
        ), driver AS (
         SELECT hydro_object.hdo_id AS db_id,
            drivers.naam
           FROM (((public.hydro_object
             LEFT JOIN public.swb_pressure ON (((hydro_object.hdo_id = swb_pressure.swb_id) AND (swb_pressure.is_significant = true))))
             LEFT JOIN public.sw_pressure_type_driver ON ((swb_pressure.sprs_id = sw_pressure_type_driver.sprs_id)))
             LEFT JOIN domains.drivers ON ((drivers.driver_id = sw_pressure_type_driver.driver_id)))
          WHERE ((hydro_object.wkrv_id = 13) AND ((hydro_object.hydro_object_type)::text = 'SurfaceWaterBody'::text))
          ORDER BY hydro_object.hdo_id
        ), driver_aant_ruw AS (
         SELECT "left"((hdo_rbd2_1.inspire_id_local_id)::text, 4) AS rbd,
            substr(objectives_exemption_type_1.description, 8, 4) AS art,
            count(driver_1.naam) AS aant
           FROM (((((((public.hydro_object hdo_rbd2_1
             LEFT JOIN public.objectives_exemption_type objectives_exemption_type_1 ON ((1 = 1)))
             LEFT JOIN public.swb_exemption swce_1 ON ((objectives_exemption_type_1.obex_id = swce_1.obex_id)))
             LEFT JOIN swb_oordeel swb_oordeel_1 ON ((swce_1.swb_id = swb_oordeel_1.swb_id)))
             LEFT JOIN public.water_body water_body_1 ON ((water_body_1.wbd_id = swb_oordeel_1.swb_id)))
             LEFT JOIN public.river_basin_disrict rbd_1 ON ((rbd_1.rbd_id = water_body_1.rbd_id)))
             LEFT JOIN public.hydro_object hdo_rbd_1 ON ((rbd_1.rbd_id = hdo_rbd_1.hdo_id)))
             LEFT JOIN driver driver_1 ON ((swb_oordeel_1.swb_id = driver_1.db_id)))
          GROUP BY ("left"((hdo_rbd2_1.inspire_id_local_id)::text, 4)), (substr(objectives_exemption_type_1.description, 8, 4)), driver_1.naam, hdo_rbd2_1.wkrv_id, hdo_rbd2_1.hydro_object_type, hdo_rbd2_1.inspire_id_local_id
         HAVING ((hdo_rbd2_1.wkrv_id = 13) AND ((hdo_rbd2_1.hydro_object_type)::text = 'RiverBasinDistrict'::text) AND ((hdo_rbd2_1.inspire_id_local_id)::text ~~ 'NL%'::text))
          ORDER BY ("left"((hdo_rbd2_1.inspire_id_local_id)::text, 4)), (substr(objectives_exemption_type_1.description, 8, 4))
        ), driver_aant AS (
         SELECT DISTINCT ON (driver_aant_ruw.rbd, driver_aant_ruw.art) driver_aant_ruw.rbd,
            driver_aant_ruw.art,
            driver_aant_ruw.aant
           FROM driver_aant_ruw
          ORDER BY driver_aant_ruw.rbd, driver_aant_ruw.art, driver_aant_ruw.aant DESC
        )
 SELECT DISTINCT ON (("left"((hdo_rbd2.inspire_id_local_id)::text, 4)), driver.naam) (hdo_rbd2.hdo_id)::text AS "sWExemptionsID",
        CASE
            WHEN (driver_aant.aant = 0) THEN 'Exemption not applied'::text
            ELSE
            CASE driver.naam
                WHEN 'Landbouw'::text THEN 'Agriculture'::text
                WHEN 'Klimaatverandering'::text THEN 'Climate change'::text
                WHEN 'Energie (hydropower)'::text THEN 'Energy - hydropower'::text
                WHEN 'Energie (geen hydropower)'::text THEN 'Energy - non-hydropower'::text
                WHEN 'Visserij & Aquacultuur'::text THEN 'Fisheries and aquaculture'::text
                WHEN 'Hoogwaterbescherming'::text THEN 'Flood protection'::text
                WHEN 'Bosbouw'::text THEN 'Forestry'::text
                WHEN 'Industrie'::text THEN 'Industry'::text
                WHEN 'Toerisme en Recreatie'::text THEN 'Tourism and recreation'::text
                WHEN 'Transport'::text THEN 'Transport'::text
                WHEN 'Stedelijke ontwikkeling'::text THEN 'Urban development'::text
                WHEN 'Recreatie'::text THEN 'Tourism and recreation'::text
                WHEN 'Niet bekend of verouderd'::text THEN 'Unknown - other'::text
                WHEN 'Eén of meerdere'::text THEN 'Unknown - other'::text
                WHEN 'Anders'::text THEN 'Unknown - other'::text
                WHEN 'null'::text THEN 'Unknown - other'::text
                ELSE 'oeps'::text
            END
        END AS "swExemption44Driver"
   FROM ((((((((public.hydro_object hdo_rbd2
     LEFT JOIN public.objectives_exemption_type ON ((1 = 1)))
     LEFT JOIN public.swb_exemption swce ON ((objectives_exemption_type.obex_id = swce.obex_id)))
     LEFT JOIN swb_oordeel ON ((swce.swb_id = swb_oordeel.swb_id)))
     LEFT JOIN public.water_body ON ((water_body.wbd_id = swb_oordeel.swb_id)))
     LEFT JOIN public.river_basin_disrict rbd ON ((rbd.rbd_id = water_body.rbd_id)))
     LEFT JOIN public.hydro_object hdo_rbd ON ((rbd.rbd_id = hdo_rbd.hdo_id)))
     LEFT JOIN driver_aant ON ((("left"((hdo_rbd2.inspire_id_local_id)::text, 4) = driver_aant.rbd) AND (driver_aant.art = substr(objectives_exemption_type.description, 8, 4)))))
     LEFT JOIN driver ON ((swb_oordeel.swb_id = driver.db_id)))
  WHERE ((hdo_rbd2.wkrv_id = 13) AND ((hdo_rbd2.hydro_object_type)::text = 'RiverBasinDistrict'::text) AND ((hdo_rbd2.inspire_id_local_id)::text ~~ 'NL%'::text) AND (((driver.naam IS NOT NULL) AND (driver_aant.aant > 0)) OR ((driver.naam IS NULL) AND (driver_aant.aant = 0))) AND (substr(objectives_exemption_type.description, 8, 4) = '4(4)'::text) AND (rbd.international_rbd IS NOT NULL) AND (length((hdo_rbd2.inspire_id_local_id)::text) = 4))
  ORDER BY ("left"((hdo_rbd2.inspire_id_local_id)::text, 4)), driver.naam;


--
-- Name: vw_swexemptions_swexemption44impact; Type: VIEW; Schema: wfd_reporting; Owner: -
--

CREATE VIEW vw_swexemptions_swexemption44impact AS
 WITH swb_oordeel AS (
         SELECT DISTINCT ON (hdo_swb.hdo_id, sw_ecological_status.opt_id) hdo_swb.hdo_id AS swb_id,
            swb_yearly_status.year_of_status AS jaar,
            sw_ecological_status.opt_id,
            classification_type.description AS oordeel,
            waarde_bepalings_methode_type.code AS wbpm
           FROM ((((public.swb_yearly_status
             LEFT JOIN public.hydro_object hdo_swb ON ((hdo_swb.hdo_id = swb_yearly_status.swb_id)))
             JOIN public.sw_ecological_status ON ((sw_ecological_status.sys_id = swb_yearly_status.sys_id)))
             LEFT JOIN public.classification_type ON ((sw_ecological_status.swes_id = classification_type.cls_id)))
             LEFT JOIN public.waarde_bepalings_methode_type ON ((waarde_bepalings_methode_type.wbpm_id = sw_ecological_status.wbpm_id)))
          WHERE ((hdo_swb.wkrv_id = 13) AND (swb_yearly_status.year_of_status = 2015) AND ((classification_type.description)::text <> 'goed'::text))
        UNION ALL
         SELECT DISTINCT ON (hdo_swb.hdo_id, sw_chemical_substance_status.opt_id) hdo_swb.hdo_id AS swb_id,
            swb_yearly_status.year_of_status AS jaar,
            sw_chemical_substance_status.opt_id,
            classification_type.description AS oordeel,
            waarde_bepalings_methode_type.code AS wbpm
           FROM ((((public.swb_yearly_status
             LEFT JOIN public.hydro_object hdo_swb ON ((hdo_swb.hdo_id = swb_yearly_status.swb_id)))
             JOIN public.sw_chemical_substance_status ON ((sw_chemical_substance_status.sys_id = swb_yearly_status.sys_id)))
             LEFT JOIN public.classification_type ON ((sw_chemical_substance_status.swcs_id = classification_type.cls_id)))
             LEFT JOIN public.waarde_bepalings_methode_type ON ((waarde_bepalings_methode_type.wbpm_id = sw_chemical_substance_status.wbpm_id)))
          WHERE ((hdo_swb.wkrv_id = 13) AND (swb_yearly_status.year_of_status = 2015) AND ((classification_type.description)::text = 'voldoet niet'::text))
  ORDER BY 1, 3, 4 DESC
        ), swb_oordeel_i AS (
         SELECT DISTINCT ON (swb_oordeel_1.swb_id) swb_oordeel_1.swb_id,
            swb_oordeel_1.opt_id,
            swb_oordeel_1.jaar,
            swb_oordeel_1.oordeel,
            swb_oordeel_1.wbpm
           FROM swb_oordeel swb_oordeel_1
          ORDER BY swb_oordeel_1.swb_id, swb_oordeel_1.oordeel DESC
        ), impact AS (
         SELECT hydro_object.hdo_id AS db_id,
                CASE
                    WHEN (ipe.eu_xsd IS NULL) THEN
                    CASE
                        WHEN (((swb_oordeel_i.oordeel)::text = 'voldoet'::text) OR ((swb_oordeel_i.oordeel)::text = 'goed'::text)) THEN 'NOSI - No significant impact'::text
                        ELSE 'UNKN - Unknown impact type'::text
                    END
                    ELSE ipe.eu_xsd
                END AS impact_type
           FROM ((((public.hydro_object
             LEFT JOIN public.swb_pressure ON (((hydro_object.hdo_id = swb_pressure.swb_id) AND (swb_pressure.is_significant = true))))
             LEFT JOIN public.swb_pressure_impact ON ((swb_pressure.swbp_id = swb_pressure_impact.swbp_id)))
             LEFT JOIN significant_impact_enum ipe ON ((ipe.i_id = swb_pressure_impact.impact_id)))
             LEFT JOIN swb_oordeel_i ON ((swb_oordeel_i.swb_id = hydro_object.hdo_id)))
          WHERE ((hydro_object.wkrv_id = 13) AND ((hydro_object.hydro_object_type)::text = 'SurfaceWaterBody'::text))
          ORDER BY hydro_object.hdo_id, ipe.eu_xsd
        ), impact_aant_ruw AS (
         SELECT "left"((hdo_rbd2_1.inspire_id_local_id)::text, 4) AS rbd,
            substr(objectives_exemption_type_1.description, 8, 4) AS art,
            count(impact_1.impact_type) AS aant
           FROM (((((((public.hydro_object hdo_rbd2_1
             LEFT JOIN public.objectives_exemption_type objectives_exemption_type_1 ON ((1 = 1)))
             LEFT JOIN public.swb_exemption swce_1 ON ((objectives_exemption_type_1.obex_id = swce_1.obex_id)))
             LEFT JOIN swb_oordeel swb_oordeel_1 ON ((swce_1.swb_id = swb_oordeel_1.swb_id)))
             LEFT JOIN public.water_body water_body_1 ON ((water_body_1.wbd_id = swb_oordeel_1.swb_id)))
             LEFT JOIN public.river_basin_disrict rbd_1 ON ((rbd_1.rbd_id = water_body_1.rbd_id)))
             LEFT JOIN public.hydro_object hdo_rbd_1 ON ((rbd_1.rbd_id = hdo_rbd_1.hdo_id)))
             LEFT JOIN impact impact_1 ON ((swb_oordeel_1.swb_id = impact_1.db_id)))
          GROUP BY ("left"((hdo_rbd2_1.inspire_id_local_id)::text, 4)), (substr(objectives_exemption_type_1.description, 8, 4)), impact_1.impact_type, hdo_rbd2_1.wkrv_id, hdo_rbd2_1.hydro_object_type, hdo_rbd2_1.inspire_id_local_id
         HAVING ((hdo_rbd2_1.wkrv_id = 13) AND ((hdo_rbd2_1.hydro_object_type)::text = 'RiverBasinDistrict'::text) AND ((hdo_rbd2_1.inspire_id_local_id)::text ~~ 'NL%'::text))
          ORDER BY ("left"((hdo_rbd2_1.inspire_id_local_id)::text, 4)), (substr(objectives_exemption_type_1.description, 8, 4))
        ), impact_aant AS (
         SELECT DISTINCT ON (impact_aant_ruw.rbd, impact_aant_ruw.art) impact_aant_ruw.rbd,
            impact_aant_ruw.art,
            impact_aant_ruw.aant
           FROM impact_aant_ruw
          ORDER BY impact_aant_ruw.rbd, impact_aant_ruw.art, impact_aant_ruw.aant DESC
        )
 SELECT DISTINCT ON (("left"((hdo_rbd2.inspire_id_local_id)::text, 4)), impact.impact_type) (hdo_rbd2.hdo_id)::text AS "sWExemptionsID",
        CASE
            WHEN (impact_aant.aant = 0) THEN 'Not applicable'::text
            ELSE impact.impact_type
        END AS "swExemption44Impact"
   FROM ((((((((public.hydro_object hdo_rbd2
     LEFT JOIN public.objectives_exemption_type ON ((1 = 1)))
     LEFT JOIN public.swb_exemption swce ON ((objectives_exemption_type.obex_id = swce.obex_id)))
     LEFT JOIN swb_oordeel ON ((swce.swb_id = swb_oordeel.swb_id)))
     LEFT JOIN public.water_body ON ((water_body.wbd_id = swb_oordeel.swb_id)))
     LEFT JOIN public.river_basin_disrict rbd ON ((rbd.rbd_id = water_body.rbd_id)))
     LEFT JOIN public.hydro_object hdo_rbd ON ((rbd.rbd_id = hdo_rbd.hdo_id)))
     LEFT JOIN impact_aant ON ((("left"((hdo_rbd2.inspire_id_local_id)::text, 4) = impact_aant.rbd) AND (impact_aant.art = substr(objectives_exemption_type.description, 8, 4)))))
     LEFT JOIN impact ON ((swb_oordeel.swb_id = impact.db_id)))
  WHERE ((hdo_rbd2.wkrv_id = 13) AND ((hdo_rbd2.hydro_object_type)::text = 'RiverBasinDistrict'::text) AND ((hdo_rbd2.inspire_id_local_id)::text ~~ 'NL%'::text) AND (((impact.impact_type IS NOT NULL) AND (impact_aant.aant > 0)) OR ((impact.impact_type IS NULL) AND (impact_aant.aant = 0))) AND (substr(objectives_exemption_type.description, 8, 4) = '4(4)'::text) AND (rbd.international_rbd IS NOT NULL) AND (length((hdo_rbd2.inspire_id_local_id)::text) = 4))
  ORDER BY ("left"((hdo_rbd2.inspire_id_local_id)::text, 4)), impact.impact_type;


--
-- Name: vw_swexemptions_swexemption45driver; Type: VIEW; Schema: wfd_reporting; Owner: -
--

CREATE VIEW vw_swexemptions_swexemption45driver AS
 SELECT DISTINCT ON (hdo_rbd2.hdo_id) ((hdo_rbd2.hdo_id)::text || '5'::text) AS "sWExemptionsID",
    'Exemption not applied'::text AS "swExemption45Driver"
   FROM (((((public.hydro_object hdo_rbd2
     LEFT JOIN public.objectives_exemption_type ON ((1 = 1)))
     LEFT JOIN public.gwb_chemical_exemption gwce ON ((objectives_exemption_type.obex_id = gwce.obex_id)))
     LEFT JOIN public.water_body ON ((water_body.wbd_id = gwce.gwb_id)))
     LEFT JOIN public.river_basin_disrict rbd ON ((rbd.rbd_id = water_body.rbd_id)))
     LEFT JOIN public.hydro_object hdo_rbd ON ((rbd.rbd_id = hdo_rbd.hdo_id)))
  WHERE ((hdo_rbd2.wkrv_id = 13) AND ((hdo_rbd2.hydro_object_type)::text = 'RiverBasinDistrict'::text) AND ((hdo_rbd2.inspire_id_local_id)::text ~~ 'NL%'::text) AND (rbd.international_rbd IS NOT NULL) AND (length((hdo_rbd2.inspire_id_local_id)::text) = 4))
  ORDER BY hdo_rbd2.hdo_id;


--
-- Name: vw_swexemptions_swexemption45impact; Type: VIEW; Schema: wfd_reporting; Owner: -
--

CREATE VIEW vw_swexemptions_swexemption45impact AS
 SELECT DISTINCT ON (hdo_rbd2.hdo_id) ((hdo_rbd2.hdo_id)::text || '5'::text) AS "sWExemptionsID",
    'Not applicable'::text AS "swExemption45Impact",
    hdo_rbd2.inspire_id_local_id
   FROM (((((public.hydro_object hdo_rbd2
     LEFT JOIN public.objectives_exemption_type ON ((1 = 1)))
     LEFT JOIN public.gwb_chemical_exemption gwce ON ((objectives_exemption_type.obex_id = gwce.obex_id)))
     LEFT JOIN public.water_body ON ((water_body.wbd_id = gwce.gwb_id)))
     LEFT JOIN public.river_basin_disrict rbd ON ((rbd.rbd_id = water_body.rbd_id)))
     LEFT JOIN public.hydro_object hdo_rbd ON ((rbd.rbd_id = hdo_rbd.hdo_id)))
  WHERE ((hdo_rbd2.wkrv_id = 13) AND ((hdo_rbd2.hydro_object_type)::text = 'RiverBasinDistrict'::text) AND ((hdo_rbd2.inspire_id_local_id)::text ~~ 'NL%'::text) AND (rbd.international_rbd IS NOT NULL) AND (length((hdo_rbd2.inspire_id_local_id)::text) = 4))
  ORDER BY hdo_rbd2.hdo_id;


--
-- Name: vw_swexemptions_swexemption46; Type: VIEW; Schema: wfd_reporting; Owner: -
--

CREATE VIEW vw_swexemptions_swexemption46 AS
 WITH e46_1 AS (
         SELECT DISTINCT ON (("left"((hdo_rbd2.inspire_id_local_id)::text, 4)), (substr(objectives_exemption_type.description, 8, 4)), gwce.obex_id) ((hdo_rbd2.hdo_id)::text || substr(objectives_exemption_type.description, 10, 1)) AS "sWExemptionsID",
                CASE
                    WHEN (gwce.obex_id = ANY (ARRAY[4, 5, 6])) THEN 'Yes (prolonged droughts)'::text
                    ELSE 'Article 4(6) has not been applied'::text
                END AS "swExemption46"
           FROM (((((public.hydro_object hdo_rbd2
             LEFT JOIN public.objectives_exemption_type ON ((1 = 1)))
             LEFT JOIN public.swb_exemption gwce ON ((objectives_exemption_type.obex_id = gwce.obex_id)))
             LEFT JOIN public.water_body ON ((water_body.wbd_id = gwce.swb_id)))
             LEFT JOIN public.river_basin_disrict rbd ON ((rbd.rbd_id = water_body.rbd_id)))
             LEFT JOIN public.hydro_object hdo_rbd ON ((rbd.rbd_id = hdo_rbd.hdo_id)))
          WHERE ((hdo_rbd2.wkrv_id = 13) AND ((hdo_rbd2.hydro_object_type)::text = 'RiverBasinDistrict'::text) AND ((hdo_rbd2.inspire_id_local_id)::text ~~ 'NL%'::text) AND (substr(objectives_exemption_type.description, 8, 4) = '4(6)'::text))
          ORDER BY ("left"((hdo_rbd2.inspire_id_local_id)::text, 4)), (substr(objectives_exemption_type.description, 8, 4)), gwce.obex_id
        ), e46_2 AS (
         SELECT DISTINCT ON (("left"((hdo_rbd2.inspire_id_local_id)::text, 4)), (substr(objectives_exemption_type.description, 8, 4)), gwce.obex_id) ((hdo_rbd2.hdo_id)::text || substr(objectives_exemption_type.description, 10, 1)) AS "sWExemptionsID",
                CASE
                    WHEN (gwce.obex_id = ANY (ARRAY[4, 5, 6])) THEN 'Yes (extreme floods)'::text
                    ELSE 'Article 4(6) has not been applied'::text
                END AS "swExemption46"
           FROM (((((public.hydro_object hdo_rbd2
             LEFT JOIN public.objectives_exemption_type ON ((1 = 1)))
             LEFT JOIN public.swb_exemption gwce ON ((objectives_exemption_type.obex_id = gwce.obex_id)))
             LEFT JOIN public.water_body ON ((water_body.wbd_id = gwce.swb_id)))
             LEFT JOIN public.river_basin_disrict rbd ON ((rbd.rbd_id = water_body.rbd_id)))
             LEFT JOIN public.hydro_object hdo_rbd ON ((rbd.rbd_id = hdo_rbd.hdo_id)))
          WHERE ((hdo_rbd2.wkrv_id = 13) AND ((hdo_rbd2.hydro_object_type)::text = 'RiverBasinDistrict'::text) AND ((hdo_rbd2.inspire_id_local_id)::text ~~ 'NL%'::text) AND (substr(objectives_exemption_type.description, 8, 4) = '4(6)'::text))
          ORDER BY ("left"((hdo_rbd2.inspire_id_local_id)::text, 4)), (substr(objectives_exemption_type.description, 8, 4)), gwce.obex_id
        ), e46_3 AS (
         SELECT DISTINCT ON (("left"((hdo_rbd2.inspire_id_local_id)::text, 4)), (substr(objectives_exemption_type.description, 8, 4)), gwce.obex_id) ((hdo_rbd2.hdo_id)::text || substr(objectives_exemption_type.description, 10, 1)) AS "sWExemptionsID",
                CASE
                    WHEN (gwce.obex_id = ANY (ARRAY[4, 5, 6])) THEN 'Yes (accidents)'::text
                    ELSE 'Article 4(6) has not been applied'::text
                END AS "swExemption46"
           FROM (((((public.hydro_object hdo_rbd2
             LEFT JOIN public.objectives_exemption_type ON ((1 = 1)))
             LEFT JOIN public.swb_exemption gwce ON ((objectives_exemption_type.obex_id = gwce.obex_id)))
             LEFT JOIN public.water_body ON ((water_body.wbd_id = gwce.swb_id)))
             LEFT JOIN public.river_basin_disrict rbd ON ((rbd.rbd_id = water_body.rbd_id)))
             LEFT JOIN public.hydro_object hdo_rbd ON ((rbd.rbd_id = hdo_rbd.hdo_id)))
          WHERE ((hdo_rbd2.wkrv_id = 13) AND ((hdo_rbd2.hydro_object_type)::text = 'RiverBasinDistrict'::text) AND ((hdo_rbd2.inspire_id_local_id)::text ~~ 'NL%'::text) AND (substr(objectives_exemption_type.description, 8, 4) = '4(6)'::text))
          ORDER BY ("left"((hdo_rbd2.inspire_id_local_id)::text, 4)), (substr(objectives_exemption_type.description, 8, 4)), gwce.obex_id
        ), e46 AS (
         SELECT e46_1."sWExemptionsID",
            e46_1."swExemption46"
           FROM e46_1
        UNION ALL
         SELECT e46_2."sWExemptionsID",
            e46_2."swExemption46"
           FROM e46_2
        UNION ALL
         SELECT e46_3."sWExemptionsID",
            e46_3."swExemption46"
           FROM e46_3
        )
 SELECT DISTINCT ON (e46."sWExemptionsID", e46."swExemption46") e46."sWExemptionsID",
    e46."swExemption46"
   FROM e46
  ORDER BY e46."sWExemptionsID", e46."swExemption46";


--
-- Name: vw_swexemptions_swexemption47; Type: VIEW; Schema: wfd_reporting; Owner: -
--

CREATE VIEW vw_swexemptions_swexemption47 AS
 WITH e47 AS (
         SELECT DISTINCT ON (("left"((hdo_rbd2.inspire_id_local_id)::text, 4)), gwce.obex_id) (hdo_rbd2.hdo_id)::text AS "sWExemptionsID",
                CASE
                    WHEN (gwce.obex_id = ANY (ARRAY[7, 8])) THEN 'Other'::text
                    ELSE 'Article 4(7) has not been applied'::text
                END AS "swExemption47"
           FROM (((((public.hydro_object hdo_rbd2
             LEFT JOIN public.objectives_exemption_type ON ((1 = 1)))
             LEFT JOIN public.swb_exemption gwce ON ((objectives_exemption_type.obex_id = gwce.obex_id)))
             LEFT JOIN public.water_body ON ((water_body.wbd_id = gwce.swb_id)))
             LEFT JOIN public.river_basin_disrict rbd ON ((rbd.rbd_id = water_body.rbd_id)))
             LEFT JOIN public.hydro_object hdo_rbd ON ((rbd.rbd_id = hdo_rbd.hdo_id)))
          WHERE ((hdo_rbd2.wkrv_id = 13) AND ((hdo_rbd2.hydro_object_type)::text = 'RiverBasinDistrict'::text) AND ((hdo_rbd2.inspire_id_local_id)::text ~~ 'NL%'::text) AND (substr(objectives_exemption_type.description, 8, 4) = '4(6)'::text))
          ORDER BY ("left"((hdo_rbd2.inspire_id_local_id)::text, 4)), gwce.obex_id
        )
 SELECT DISTINCT ON (e47."sWExemptionsID", e47."swExemption47") e47."sWExemptionsID",
    e47."swExemption47"
   FROM e47
  ORDER BY e47."sWExemptionsID", e47."swExemption47";


--
-- Name: vw_swphysicochemicalqe; Type: VIEW; Schema: wfd_reporting; Owner: -
--

CREATE VIEW vw_swphysicochemicalqe AS
 WITH doelen AS (
         SELECT DISTINCT ON (norm_value.nrmv_id, vw_waargenomen_eigenschap_db_id."DB_ID", classification_type.description) vw_waterlichamen.omschrijving AS "Waterlichaam_Naam",
            "left"((vw_oppervlaktewaterlichamen.stroomgebieddistrict)::text, 4) AS sgb,
            vw_oppervlaktewaterlichamen.type AS watertype,
            vw_oppervlaktewaterlichamen.referentietype AS doeltype,
            vw_oppervlaktewaterlichamen.waterlichaam_status AS 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 parameter,
            waarde_bewerkings_methode_type.code AS wbwm,
            eenheid_type.code AS eenheid,
            classification_type.description AS klasse,
            (bepaling_grens_type.code)::text AS klasse_onder_bep,
            (norm_value.lowerbound_value)::text AS klasse_onder,
            (bgt.code)::text AS klasse_boven_bep,
            (norm_value.upperbound_value)::text AS klasse_boven,
            norm.wkrv_id AS versie,
            norm.observed_property AS opt_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 jaar,
            vw_waterlichamen.identificatie AS owmident,
            vw_waterlichamen.omschrijving AS owmnaam
           FROM ((((((((((((((((((public.norm_value
             LEFT JOIN public.norm ON ((norm_value.nrm_id = norm.nrm_id)))
             LEFT JOIN public.norm_feature ON ((norm_feature.nrm_id = norm.nrm_id)))
             LEFT JOIN public.vw_waargenomen_eigenschap_db_id ON ((vw_waargenomen_eigenschap_db_id."DB_ID" = norm.observed_property)))
             LEFT JOIN public.vw_waterlichamen ON ((vw_waterlichamen.db_id = norm_feature.hdo_id)))
             LEFT JOIN public.vw_oppervlaktewaterlichamen ON ((vw_oppervlaktewaterlichamen.db_id = norm_feature.hdo_id)))
             LEFT JOIN public.level_of_area_type ON ((level_of_area_type.loa_id = norm.defined_at_level_id)))
             LEFT JOIN public.norm_groep_type ON ((norm_groep_type.nmgp_id = norm.norm_groep_id)))
             LEFT JOIN public.waarde_bewerkings_methode_type ON ((waarde_bewerkings_methode_type.wbm_id = norm_value.value_processing_method)))
             LEFT JOIN public.eenheid_type ON ((eenheid_type.eenh_id = norm_value.lowerbound_uom_id)))
             LEFT JOIN public.compartiment_type ON ((compartiment_type.cptm_id = norm_value.cptm_id)))
             LEFT JOIN public.classification_type ON ((classification_type.cls_id = norm_value.norm_klasse_id)))
             LEFT JOIN public.bepaling_grens_type ON ((bepaling_grens_type.bpg_id = norm_value.lowerbound_limit_symbol_id)))
             LEFT JOIN public.bepaling_grens_type bgt ON ((bgt.bpg_id = norm_value.upperbound_limit_symbol_id)))
             LEFT JOIN public.namespace_type ON ((namespace_type.ns_id = vw_waterlichamen.waterbeheerder_code)))
             JOIN public.competentauthority_namespacetype ON ((competentauthority_namespacetype.ns_id = vw_waterlichamen.waterbeheerder_code)))
             JOIN public.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 public.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 public.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())) AND (norm.wkrv_id = 13) AND ((classification_type.description)::text = 'goed'::text) AND (norm.observed_property = ANY (ARRAY[619, 4212, 3685, 632, 3773, 2948, 579, 3841])))
          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
        )
 SELECT
        CASE doelen.opt_id
            WHEN 619 THEN 'QE3-1-6-1-5 - Total Nitrogen'::text
            WHEN 4212 THEN 'QE3-1-3-1 - Oxygen saturation (%)'::text
            WHEN 3685 THEN 'QE3-1-5-2 - pH'::text
            WHEN 632 THEN 'QE3-1-6-2-2 - Total Phosphorous'::text
            WHEN 3773 THEN 'QE3-1-2-1 - Water temperature (Celsius)'::text
            WHEN 2948 THEN 'QE3-1-6-4 - Other determinand for nutrient conditions'::text
            WHEN 3841 THEN 'QE3-1-1-1 - Secchi disk depth'::text
            WHEN 579 THEN 'QE3-1-4-2 - Other determinand for salinity'::text
            ELSE 'oeps'::text
        END AS "physChemQECode",
        CASE doelen.opt_id
            WHEN 2948 THEN 'DIN - Dissolved Inorganic Nitrogen'::text
            WHEN 579 THEN 'Chloride'::text
            ELSE NULL::text
        END AS "physChemQEOther",
        CASE
            WHEN ((doelen.doeltype)::text ~~ 'R%'::text) THEN 'Yes'::text
            ELSE 'No'::text
        END AS "physChemCategoryRW",
        CASE
            WHEN ((doelen.doeltype)::text ~~ 'M%'::text) THEN 'Yes'::text
            ELSE 'No'::text
        END AS "physChemCategoryLW",
        CASE
            WHEN ((doelen.doeltype)::text ~~ 'O%'::text) THEN 'Yes'::text
            ELSE 'No'::text
        END AS "physChemCategoryTW",
        CASE
            WHEN ((doelen.doeltype)::text ~~ 'K%'::text) THEN 'Yes'::text
            ELSE 'No'::text
        END AS "physChemCategoryCW",
    (((doelen.doeltype)::text || '|'::text) || (doelen.owmident)::text) AS "physChemTypeCode",
        CASE
            WHEN (doelen.klasse_onder IS NOT NULL) THEN
            CASE
                WHEN (doelen.klasse_boven IS NOT NULL) THEN concat(doelen.klasse_onder_bep, ' ', doelen.klasse_onder, ' | ', doelen.klasse_boven_bep, ' ', doelen.klasse_boven)
                ELSE concat(doelen.klasse_onder_bep, ' ', doelen.klasse_onder)
            END
            ELSE concat(doelen.klasse_boven_bep, ' ', doelen.klasse_boven)
        END AS "physChemValue",
        CASE doelen.opt_id
            WHEN 619 THEN 'mg{N}/L'::text
            WHEN 4212 THEN '%{saturation}'::text
            WHEN 632 THEN 'mg{P}/L'::text
            WHEN 2948 THEN 'mg{N}/L'::text
            WHEN 3841 THEN 'm'::text
            WHEN 579 THEN 'mg/L'::text
            WHEN 3773 THEN 'CEL'::text
            WHEN 3685 THEN 'pH'::text
            ELSE 'oeps'::text
        END AS "physChemQEUnit",
    NULL::text AS "physChemQEUnitOther",
        CASE doelen.opt_id
            WHEN 619 THEN 'AA-EQS'::text
            WHEN 4212 THEN 'AA-EQS'::text
            WHEN 3685 THEN 'MAC-EQS'::text
            WHEN 632 THEN 'AA-EQS'::text
            WHEN 3773 THEN 'MAC-EQS'::text
            WHEN 2948 THEN 'AA-EQS'::text
            WHEN 3841 THEN 'AA-EQS'::text
            WHEN 579 THEN 'AA-EQS'::text
            ELSE 'oeps'::text
        END AS "physChemStandardType",
    NULL::text AS "physChemStandardOther",
    'Yes'::text AS "physChemGMBoundary",
    doelen.sgb
   FROM doelen
  ORDER BY doelen.owmident, doelen.parameter;


--
-- Name: vw_swsupportingqe; Type: VIEW; Schema: wfd_reporting; Owner: -
--

CREATE VIEW vw_swsupportingqe AS
 WITH stt AS (
         SELECT DISTINCT ON (("left"((stt.code)::text, 1)), wfd_qe_swtype.opt_id) wfd_qe_swtype.opt_id,
            "left"((stt.code)::text, 1) AS code,
            wfd_qe_swtype.is_applicable,
            stt.swc_id
           FROM (public.sw_typology_type stt
             LEFT JOIN public.wfd_qe_swtype ON ((stt.styp_id = wfd_qe_swtype.swt_id)))
          ORDER BY ("left"((stt.code)::text, 1)), wfd_qe_swtype.opt_id, wfd_qe_swtype.is_applicable DESC
        ), qe_rel AS (
         SELECT
                CASE opt.opt_id
                    WHEN 579 THEN 'QE3-1-4 - Salinity conditions'::text
                    WHEN 619 THEN 'QE3-1-6 - Nutrient conditions'::text
                    WHEN 632 THEN 'QE3-1-6 - Nutrient conditions'::text
                    WHEN 2948 THEN 'QE3-1-6 - Nutrient conditions'::text
                    WHEN 3685 THEN 'QE3-1-5 - Acidification status'::text
                    WHEN 4212 THEN 'QE3-1-3 - Oxygenation conditions'::text
                    WHEN 3841 THEN 'QE3-1-1 - Transparency conditions'::text
                    WHEN 3773 THEN 'QE3-1-2 - Thermal conditions'::text
                    ELSE NULL::text
                END AS "supportingQECode",
                CASE
                    WHEN (stt_rw.is_applicable = true) THEN 'Yes'::text
                    ELSE 'No'::text
                END AS "supportingQECategoryRW",
                CASE
                    WHEN (stt_lw.is_applicable = true) THEN 'Yes'::text
                    ELSE 'No'::text
                END AS "supportingQECategoryLW",
                CASE
                    WHEN (stt_tw.is_applicable = true) THEN 'Yes'::text
                    ELSE 'No'::text
                END AS "supportingQECategoryTW",
                CASE
                    WHEN (stt_cw.is_applicable = true) THEN 'Yes'::text
                    ELSE 'No'::text
                END AS "supportingQECategoryCW",
            NULL::unknown AS "supportingQESensitivityBQE"
           FROM ((((public.observed_property_type opt
             LEFT JOIN stt stt_cw ON (((stt_cw.code = 'K'::text) AND (stt_cw.opt_id = opt.opt_id))))
             LEFT JOIN stt stt_lw ON (((stt_lw.code = 'M'::text) AND (stt_lw.opt_id = opt.opt_id))))
             LEFT JOIN stt stt_rw ON (((stt_rw.code = 'R'::text) AND (stt_rw.opt_id = opt.opt_id))))
             LEFT JOIN stt stt_tw ON (((stt_tw.code = 'O'::text) AND (stt_tw.opt_id = opt.opt_id))))
          WHERE (opt.opt_id = ANY (ARRAY[579, 619, 632, 3685, 4212, 3841, 3773, 2948]))
        )
 SELECT DISTINCT ON (qe_rel."supportingQECode") qe_rel."supportingQECode",
    qe_rel."supportingQECategoryRW",
    qe_rel."supportingQECategoryLW",
        CASE
            WHEN (qe_rel."supportingQECode" = 'QE3-1-6 - Nutrient conditions'::text) THEN 'Yes'::text
            ELSE qe_rel."supportingQECategoryTW"
        END AS "supportingQECategoryTW",
        CASE
            WHEN (qe_rel."supportingQECode" = 'QE3-1-6 - Nutrient conditions'::text) THEN 'Yes'::text
            ELSE qe_rel."supportingQECategoryCW"
        END AS "supportingQECategoryCW"
   FROM qe_rel
  ORDER BY qe_rel."supportingQECode", qe_rel."supportingQECategoryLW" DESC, qe_rel."supportingQECategoryRW" DESC,
        CASE
            WHEN (qe_rel."supportingQECode" = 'QE3-1-6 - Nutrient conditions'::text) THEN 'Yes'::text
            ELSE qe_rel."supportingQECategoryTW"
        END DESC,
        CASE
            WHEN (qe_rel."supportingQECode" = 'QE3-1-6 - Nutrient conditions'::text) THEN 'Yes'::text
            ELSE qe_rel."supportingQECategoryCW"
        END DESC;


--
-- Name: vw_swtype; Type: VIEW; Schema: wfd_reporting; Owner: -
--

CREATE VIEW vw_swtype AS
 SELECT sw_typology_type.code AS "swTypeCode",
    sw_typology_type.description AS "swTypeDescription",
        CASE
            WHEN (eu_intercalibration_type.eu_xsd IS NULL) THEN 'Not applicable'::character varying
            ELSE eu_intercalibration_type.eu_xsd
        END AS "swIntercalibrationType",
        CASE "left"((sw_typology_type.code)::text, 1)
            WHEN 'K'::text THEN 'CW'::text
            WHEN 'O'::text THEN 'TW'::text
            WHEN 'M'::text THEN 'LW'::text
            WHEN 'R'::text THEN 'RW'::text
            ELSE 'oeps'::text
        END AS "swTypeCategory",
    NULL::text AS "swTypeSpecificReferenceConditionsForBQEs",
    NULL::text AS "swTypeSpecificReferenceConditionsForHyMoQEs",
    NULL::text AS "swTypeSpecificReferenceConditionsForPhysChemQEs"
   FROM public.sw_typology_type,
    public.eu_intercalibration_type
  WHERE (eu_intercalibration_type.icalt = sw_typology_type.icalt_id);



--
-- Name: suth_id; Type: DEFAULT; Schema: beheer; Owner: -
--

ALTER TABLE ONLY stat_user_tables_hist ALTER COLUMN suth_id SET DEFAULT nextval('stat_user_tables_hist_suth_id_seq'::regclass);



--
-- Name: bmm_id; Type: DEFAULT; Schema: domains; Owner: -
--

ALTER TABLE ONLY bemonsteringsmethode ALTER COLUMN bmm_id SET DEFAULT nextval('bemonsteringsmethode_bmm_id_seq'::regclass);


--
-- Name: ctf_id; Type: DEFAULT; Schema: domains; Owner: -
--

ALTER TABLE ONLY certificeringscode ALTER COLUMN ctf_id SET DEFAULT nextval('certificeringscode_ctf_id_seq'::regclass);


--
-- Name: clt_id; Type: DEFAULT; Schema: domains; Owner: -
--

ALTER TABLE ONLY confidence_level_type ALTER COLUMN clt_id SET DEFAULT nextval('confidence_level_type_clt_id_seq'::regclass);


--
-- Name: driver_id; Type: DEFAULT; Schema: domains; Owner: -
--

ALTER TABLE ONLY drivers ALTER COLUMN driver_id SET DEFAULT nextval('drivers_driver_id_seq'::regclass);


--
-- Name: impact_id; Type: DEFAULT; Schema: domains; Owner: -
--

ALTER TABLE ONLY impacts ALTER COLUMN impact_id SET DEFAULT nextval('impacts_impact_id_seq'::regclass);


--
-- Name: idd_id; Type: DEFAULT; Schema: domains; Owner: -
--

ALTER TABLE ONLY indicator_descriptor ALTER COLUMN idd_id SET DEFAULT nextval('indicator_descriptor_idd_id_seq'::regclass);


--
-- Name: ltwb_id; Type: DEFAULT; Schema: domains; Owner: -
--

ALTER TABLE ONLY locatietype_waardebepaling ALTER COLUMN ltwb_id SET DEFAULT nextval('locatietype_waardebepaling_ltwb_id_seq'::regclass);


--
-- Name: mar_id; Type: DEFAULT; Schema: domains; Owner: -
--

ALTER TABLE ONLY meetapparaat ALTER COLUMN mar_id SET DEFAULT nextval('meetapparaat_mar_id_seq'::regclass);


--
-- Name: mbm_id; Type: DEFAULT; Schema: domains; Owner: -
--

ALTER TABLE ONLY monsterbewerkingsmethode ALTER COLUMN mbm_id SET DEFAULT nextval('monsterbewerkingsmethode_mbm_id_seq'::regclass);


--
-- Name: mvb_id; Type: DEFAULT; Schema: domains; Owner: -
--

ALTER TABLE ONLY monstervoorbehandeling ALTER COLUMN mvb_id SET DEFAULT nextval('monstervoorbehandeling_mvb_id_seq'::regclass);


--
-- Name: org_id; Type: DEFAULT; Schema: domains; Owner: -
--

ALTER TABLE ONLY orgaan ALTER COLUMN org_id SET DEFAULT nextval('orgaan_org_id_seq'::regclass);


--
-- Name: scm_id; Type: DEFAULT; Schema: domains; Owner: -
--

ALTER TABLE ONLY status_change_motivation_type ALTER COLUMN scm_id SET DEFAULT nextval('status_change_motivation_type_scm_id_seq'::regclass);


--
-- Name: var_id; Type: DEFAULT; Schema: domains; Owner: -
--

ALTER TABLE ONLY veldapparaat ALTER COLUMN var_id SET DEFAULT nextval('veldapparaat_var_id_seq'::regclass);


--
-- Name: wbpt_id; Type: DEFAULT; Schema: domains; Owner: -
--

ALTER TABLE ONLY waardebepalingstechniek ALTER COLUMN wbpt_id SET DEFAULT nextval('waardebepalingstechniek_wbpt_id_seq'::regclass);



--
-- Name: cym_id; Type: DEFAULT; Schema: krm; Owner: -
--

ALTER TABLE ONLY cycle_description ALTER COLUMN cym_id SET DEFAULT nextval('cycle_description_cym_id_seq'::regclass);



--
-- Name: pot_id; Type: DEFAULT; Schema: monprog; Owner: -
--

ALTER TABLE ONLY planned_observation_time ALTER COLUMN pot_id SET DEFAULT nextval('planned_observation_time_pot_id_seq'::regclass);



--
-- Name: id; Type: DEFAULT; Schema: public; Owner: -
--

ALTER TABLE ONLY "Actie" ALTER COLUMN id SET DEFAULT nextval('"Actie_id_seq"'::regclass);


--
-- Name: id; Type: DEFAULT; Schema: public; Owner: -
--

ALTER TABLE ONLY "VerwerkingsVerslag" ALTER COLUMN id SET DEFAULT nextval('"VerwerkingsVerslag_id_seq"'::regclass);


--
-- Name: id; Type: DEFAULT; Schema: public; Owner: -
--

ALTER TABLE ONLY "VerwerkingsVerslagParameter" ALTER COLUMN id SET DEFAULT nextval('"VerwerkingsVerslagParameter_id_seq"'::regclass);


--
-- Name: id; Type: DEFAULT; Schema: public; Owner: -
--

ALTER TABLE ONLY "VerwerkingsVerslagRegel" ALTER COLUMN id SET DEFAULT nextval('"VerwerkingsVerslagRegel_id_seq"'::regclass);


--
-- Name: id; Type: DEFAULT; Schema: public; Owner: -
--

ALTER TABLE ONLY "VerwerkingsVerslagRegelSoort" ALTER COLUMN id SET DEFAULT nextval('"VerwerkingsVerslagRegelSoort_id_seq"'::regclass);


--
-- Name: id; Type: DEFAULT; Schema: public; Owner: -
--

ALTER TABLE ONLY "VerwerkingsVerslagStatus" ALTER COLUMN id SET DEFAULT nextval('"VerwerkingsVerslagStatus_id_seq"'::regclass);


--
-- Name: id; Type: DEFAULT; Schema: public; Owner: -
--

ALTER TABLE ONLY _hab_ds ALTER COLUMN id SET DEFAULT nextval('_hab_ds_id_seq'::regclass);


--
-- Name: id; Type: DEFAULT; Schema: public; Owner: -
--

ALTER TABLE ONLY _vog_ds ALTER COLUMN id SET DEFAULT nextval('_vog_ds_id_seq'::regclass);


--
-- Name: atl_id; Type: DEFAULT; Schema: public; Owner: -
--

ALTER TABLE ONLY any_thematic_link ALTER COLUMN atl_id SET DEFAULT nextval('any_thematic_link_atl_id_seq'::regclass);


--
-- Name: applicationid; Type: DEFAULT; Schema: public; Owner: -
--

ALTER TABLE ONLY application ALTER COLUMN applicationid SET DEFAULT nextval('application_applicationid_seq'::regclass);


--
-- Name: bma_id; Type: DEFAULT; Schema: public; Owner: -
--

ALTER TABLE ONLY basic_measure113a_type ALTER COLUMN bma_id SET DEFAULT nextval('basic_measure113a_type_bma_id_seq'::regclass);


--
-- Name: bpg_id; Type: DEFAULT; Schema: public; Owner: -
--

ALTER TABLE ONLY bepaling_grens_type ALTER COLUMN bpg_id SET DEFAULT nextval('bepaling_grens_type_bpg_id_seq'::regclass);


--
-- Name: bronnen_id; Type: DEFAULT; Schema: public; Owner: -
--

ALTER TABLE ONLY bronnen ALTER COLUMN bronnen_id SET DEFAULT nextval('bronnen_bronnen_id_seq'::regclass);


--
-- Name: crc_id; Type: DEFAULT; Schema: public; Owner: -
--

ALTER TABLE ONLY ca_role_code ALTER COLUMN crc_id SET DEFAULT nextval('ca_role_code_crc_id_seq'::regclass);


--
-- Name: chs_id; Type: DEFAULT; Schema: public; Owner: -
--

ALTER TABLE ONLY chemische_stof_type ALTER COLUMN chs_id SET DEFAULT nextval('chemische_stof_type_chs_id_seq'::regclass);


--
-- Name: clsg_id; Type: DEFAULT; Schema: public; Owner: -
--

ALTER TABLE ONLY classification_group_type ALTER COLUMN clsg_id SET DEFAULT nextval('classification_group_type_clsg_id_seq'::regclass);


--
-- Name: cls_id; Type: DEFAULT; Schema: public; Owner: -
--

ALTER TABLE ONLY classification_type ALTER COLUMN cls_id SET DEFAULT nextval('classification_type_cls_id_seq'::regclass);


--
-- Name: cptm_id; Type: DEFAULT; Schema: public; Owner: -
--

ALTER TABLE ONLY compartiment_type ALTER COLUMN cptm_id SET DEFAULT nextval('compartiment_type_cptm_id_seq'::regclass);


--
-- Name: ca_ns_id; Type: DEFAULT; Schema: public; Owner: -
--

ALTER TABLE ONLY competentauthority_namespacetype ALTER COLUMN ca_ns_id SET DEFAULT nextval('competentauthority_namespacetype_ca_ns_id_seq'::regclass);


--
-- Name: cog_id; Type: DEFAULT; Schema: public; Owner: -
--

ALTER TABLE ONLY condition_of_gw_type ALTER COLUMN cog_id SET DEFAULT nextval('condition_of_gw_type_cog_id_seq'::regclass);


--
-- Name: csvtransformationid; Type: DEFAULT; Schema: public; Owner: -
--

ALTER TABLE ONLY csvtransformation ALTER COLUMN csvtransformationid SET DEFAULT nextval('csvtransformation_csvtransformationid_seq'::regclass);


--
-- Name: dpr_id; Type: DEFAULT; Schema: public; Owner: -
--

ALTER TABLE ONLY depth_range_type ALTER COLUMN dpr_id SET DEFAULT nextval('depth_range_type_dpr_id_seq'::regclass);


--
-- Name: domaintable_changes_id; Type: DEFAULT; Schema: public; Owner: -
--

ALTER TABLE ONLY domaintable_changes ALTER COLUMN domaintable_changes_id SET DEFAULT nextval('domaintable_changes_domaintable_changes_id_seq'::regclass);


--
-- Name: eenh_id; Type: DEFAULT; Schema: public; Owner: -
--

ALTER TABLE ONLY eenheid_type ALTER COLUMN eenh_id SET DEFAULT nextval('eenheid_type_eenh_id_seq'::regclass);


--
-- Name: emd_id; Type: DEFAULT; Schema: public; Owner: -
--

ALTER TABLE ONLY environmental_domain_code ALTER COLUMN emd_id SET DEFAULT nextval('environmental_domain_code_emd_id_seq'::regclass);


--
-- Name: a43b_id; Type: DEFAULT; Schema: public; Owner: -
--

ALTER TABLE ONLY eu_article_43b_type ALTER COLUMN a43b_id SET DEFAULT nextval('eu_article_43b_type_a43b_id_seq'::regclass);


--
-- Name: dlt_id; Type: DEFAULT; Schema: public; Owner: -
--

ALTER TABLE ONLY eu_depth_level_type ALTER COLUMN dlt_id SET DEFAULT nextval('eu_depth_level_type_dlt_id_seq'::regclass);


--
-- Name: euf_id; Type: DEFAULT; Schema: public; Owner: -
--

ALTER TABLE ONLY eu_fund_type ALTER COLUMN euf_id SET DEFAULT nextval('eu_fund_type_euf_id_seq'::regclass);


--
-- Name: eumg_id; Type: DEFAULT; Schema: public; Owner: -
--

ALTER TABLE ONLY eu_monitoring_goal_type ALTER COLUMN eumg_id SET DEFAULT nextval('eu_monitoring_goal_type_eumg_id_seq'::regclass);


--
-- Name: mtt_id; Type: DEFAULT; Schema: public; Owner: -
--

ALTER TABLE ONLY eu_monitoring_type ALTER COLUMN mtt_id SET DEFAULT nextval('eu_monitoring_type_mtt_id_seq'::regclass);


--
-- Name: exme_id; Type: DEFAULT; Schema: public; Owner: -
--

ALTER TABLE ONLY excemption_mechanism_type ALTER COLUMN exme_id SET DEFAULT nextval('excemption_mechanism_type_exme_id_seq'::regclass);


--
-- Name: faq_item_id; Type: DEFAULT; Schema: public; Owner: -
--

ALTER TABLE ONLY faq_item ALTER COLUMN faq_item_id SET DEFAULT nextval('faq_item_faq_item_id_seq'::regclass);


--
-- Name: faq_thema_id; Type: DEFAULT; Schema: public; Owner: -
--

ALTER TABLE ONLY faq_thema ALTER COLUMN faq_thema_id SET DEFAULT nextval('faq_thema_faq_thema_id_seq'::regclass);


--
-- Name: id; Type: DEFAULT; Schema: public; Owner: -
--

ALTER TABLE ONLY generatedfactsheets ALTER COLUMN id SET DEFAULT nextval('generatedfactsheets_id_seq'::regclass);


--
-- Name: grp_id; Type: DEFAULT; Schema: public; Owner: -
--

ALTER TABLE ONLY geo_reference_process ALTER COLUMN grp_id SET DEFAULT nextval('geo_reference_process_grp_id_seq'::regclass);


--
-- Name: gfm_id; Type: DEFAULT; Schema: public; Owner: -
--

ALTER TABLE ONLY geological_formation_type ALTER COLUMN gfm_id SET DEFAULT nextval('geological_formation_type_gfm_id_seq'::regclass);


--
-- Name: grh_id; Type: DEFAULT; Schema: public; Owner: -
--

ALTER TABLE ONLY grootheid_type ALTER COLUMN grh_id SET DEFAULT nextval('grootheid_type_grh_id_seq'::regclass);


--
-- Name: gwap_id; Type: DEFAULT; Schema: public; Owner: -
--

ALTER TABLE ONLY gw_aggregated_pressure_type ALTER COLUMN gwap_id SET DEFAULT nextval('gw_aggregated_pressure_type_gwap_id_seq'::regclass);


--
-- Name: gwcs_id; Type: DEFAULT; Schema: public; Owner: -
--

ALTER TABLE ONLY gw_chemical_status ALTER COLUMN gwcs_id SET DEFAULT nextval('gw_chemical_status_gwcs_id_seq'::regclass);


--
-- Name: gprm_id; Type: DEFAULT; Schema: public; Owner: -
--

ALTER TABLE ONLY gw_pressure_requiring_supp_add_measures ALTER COLUMN gprm_id SET DEFAULT nextval('gw_pressure_requiring_supp_add_measures_gprm_id_seq'::regclass);


--
-- Name: gprs_id; Type: DEFAULT; Schema: public; Owner: -
--

ALTER TABLE ONLY gw_pressure_type ALTER COLUMN gprs_id SET DEFAULT nextval('gw_pressure_type_gprs_id_seq'::regclass);


--
-- Name: gpg_id; Type: DEFAULT; Schema: public; Owner: -
--

ALTER TABLE ONLY gw_pressures_preventing_good_status ALTER COLUMN gpg_id SET DEFAULT nextval('gw_pressures_preventing_good_status_gpg_id_seq'::regclass);


--
-- Name: gwqs_id; Type: DEFAULT; Schema: public; Owner: -
--

ALTER TABLE ONLY gw_quantity_status ALTER COLUMN gwqs_id SET DEFAULT nextval('gw_quantity_status_gwqs_id_seq'::regclass);


--
-- Name: grcf_id; Type: DEFAULT; Schema: public; Owner: -
--

ALTER TABLE ONLY gw_reason4chemical_failure ALTER COLUMN grcf_id SET DEFAULT nextval('gw_reason4chemical_failure_grcf_id_seq'::regclass);


--
-- Name: grqf_id; Type: DEFAULT; Schema: public; Owner: -
--

ALTER TABLE ONLY gw_reason4quantity_failure ALTER COLUMN grqf_id SET DEFAULT nextval('gw_reason4quantity_failure_grqf_id_seq'::regclass);


--
-- Name: gvo_id; Type: DEFAULT; Schema: public; Owner: -
--

ALTER TABLE ONLY gw_vertical_orientation_type ALTER COLUMN gvo_id SET DEFAULT nextval('gw_vertical_orientation_type_gvo_id_seq'::regclass);


--
-- Name: gwce_id; Type: DEFAULT; Schema: public; Owner: -
--

ALTER TABLE ONLY gwb_chemical_exemption ALTER COLUMN gwce_id SET DEFAULT nextval('gwb_chemical_exemption_gwce_id_seq'::regclass);


--
-- Name: gcm_id; Type: DEFAULT; Schema: public; Owner: -
--

ALTER TABLE ONLY gwb_conceptual_model ALTER COLUMN gcm_id SET DEFAULT nextval('gwb_conceptual_model_gcm_id_seq'::regclass);


--
-- Name: gwbp_id; Type: DEFAULT; Schema: public; Owner: -
--

ALTER TABLE ONLY gwb_pressure ALTER COLUMN gwbp_id SET DEFAULT nextval('gwb_pressure_gwbp_id_seq'::regclass);


--
-- Name: gqe_id; Type: DEFAULT; Schema: public; Owner: -
--

ALTER TABLE ONLY gwb_quantitative_exemption ALTER COLUMN gqe_id SET DEFAULT nextval('gwb_quantitative_exemption_gqe_id_seq'::regclass);


--
-- Name: gys_id; Type: DEFAULT; Schema: public; Owner: -
--

ALTER TABLE ONLY gwb_yearly_status ALTER COLUMN gys_id SET DEFAULT nextval('gwb_yearly_status_gys_id_seq'::regclass);


--
-- Name: hdh_id; Type: DEFAULT; Schema: public; Owner: -
--

ALTER TABLE ONLY hoedanigheid_type ALTER COLUMN hdh_id SET DEFAULT nextval('hoedanigheid_type_hdh_id_seq'::regclass);


--
-- Name: hdo_id; Type: DEFAULT; Schema: public; Owner: -
--

ALTER TABLE ONLY hydro_object ALTER COLUMN hdo_id SET DEFAULT nextval('hydro_object_hdo_id_seq'::regclass);


--
-- Name: importruleid; Type: DEFAULT; Schema: public; Owner: -
--

ALTER TABLE ONLY importrule ALTER COLUMN importruleid SET DEFAULT nextval('importrule_importruleid_seq'::regclass);


--
-- Name: importtypeid; Type: DEFAULT; Schema: public; Owner: -
--

ALTER TABLE ONLY importtype ALTER COLUMN importtypeid SET DEFAULT nextval('importtype_importtypeid_seq'::regclass);


--
-- Name: isac_id; Type: DEFAULT; Schema: public; Owner: -
--

ALTER TABLE ONLY info_stream_activity ALTER COLUMN isac_id SET DEFAULT nextval('info_stream_activity_isac_id_seq'::regclass);


--
-- Name: ims_id; Type: DEFAULT; Schema: public; Owner: -
--

ALTER TABLE ONLY information_stream ALTER COLUMN ims_id SET DEFAULT nextval('information_stream_ims_id_seq'::regclass);


--
-- Name: ksgbp_id; Type: DEFAULT; Schema: public; Owner: -
--

ALTER TABLE ONLY kaarten_sgbp ALTER COLUMN ksgbp_id SET DEFAULT nextval('kaarten_sgbp_ksgbp_id_seq'::regclass);


--
-- Name: kwod_id; Type: DEFAULT; Schema: public; Owner: -
--

ALTER TABLE ONLY kwaliteitsoordeel_type ALTER COLUMN kwod_id SET DEFAULT nextval('kwaliteitsoordeel_type_kwod_id_seq'::regclass);


--
-- Name: lgl_id; Type: DEFAULT; Schema: public; Owner: -
--

ALTER TABLE ONLY legislation_level_type ALTER COLUMN lgl_id SET DEFAULT nextval('legislation_level_type_lgl_id_seq'::regclass);


--
-- Name: lgr_id; Type: DEFAULT; Schema: public; Owner: -
--

ALTER TABLE ONLY legislation_reference_type ALTER COLUMN lgr_id SET DEFAULT nextval('legislation_reference_type_lgr_id_seq'::regclass);


--
-- Name: loa_id; Type: DEFAULT; Schema: public; Owner: -
--

ALTER TABLE ONLY level_of_area_type ALTER COLUMN loa_id SET DEFAULT nextval('level_of_area_type_loa_id_seq'::regclass);


--
-- Name: loggingid; Type: DEFAULT; Schema: public; Owner: -
--

ALTER TABLE ONLY logging ALTER COLUMN loggingid SET DEFAULT nextval('logging_loggingid_seq'::regclass);


--
-- Name: mzc_id; Type: DEFAULT; Schema: public; Owner: -
--

ALTER TABLE ONLY management_regulation_or_restriction_zone_collection ALTER COLUMN mzc_id SET DEFAULT nextval('management_regulation_or_restriction_zone_collection_mzc_id_seq'::regclass);


--
-- Name: measure_progress_completedid; Type: DEFAULT; Schema: public; Owner: -
--

ALTER TABLE ONLY measure_progress_completed ALTER COLUMN measure_progress_completedid SET DEFAULT nextval('measure_progress_completed_measure_progress_completedid_seq'::regclass);


--
-- Name: mst_id; Type: DEFAULT; Schema: public; Owner: -
--

ALTER TABLE ONLY measure_status_type ALTER COLUMN mst_id SET DEFAULT nextval('measure_status_type_mst_id_seq'::regclass);


--
-- Name: mmr_id; Type: DEFAULT; Schema: public; Owner: -
--

ALTER TABLE ONLY measurement_regime_type ALTER COLUMN mmr_id SET DEFAULT nextval('measurement_regime_type_mmr_id_seq'::regclass);


--
-- Name: membershipid; Type: DEFAULT; Schema: public; Owner: -
--

ALTER TABLE ONLY membership ALTER COLUMN membershipid SET DEFAULT nextval('membership_membershipid_seq'::regclass);


--
-- Name: mtm_id; Type: DEFAULT; Schema: public; Owner: -
--

ALTER TABLE ONLY monitored_measure ALTER COLUMN mtm_id SET DEFAULT nextval('monitored_measure_mtm_id_seq'::regclass);


--
-- Name: mno_id; Type: DEFAULT; Schema: public; Owner: -
--

ALTER TABLE ONLY monitoring_object ALTER COLUMN mno_id SET DEFAULT nextval('monitoring_object_mno_id_seq'::regclass);


--
-- Name: moi_id; Type: DEFAULT; Schema: public; Owner: -
--

ALTER TABLE ONLY monitoring_object_other_ids ALTER COLUMN moi_id SET DEFAULT nextval('monitoring_object_other_ids_moi_id_seq'::regclass);


--
-- Name: moqe_id; Type: DEFAULT; Schema: public; Owner: -
--

ALTER TABLE ONLY monitoring_object_quality_element ALTER COLUMN moqe_id SET DEFAULT nextval('monitoring_object_quality_element_moqe_id_seq'::regclass);


--
-- Name: ns_id; Type: DEFAULT; Schema: public; Owner: -
--

ALTER TABLE ONLY namespace_type ALTER COLUMN ns_id SET DEFAULT nextval('namespace_type_ns_id_seq'::regclass);


--
-- Name: nbl_id; Type: DEFAULT; Schema: public; Owner: -
--

ALTER TABLE ONLY natural_background_levels ALTER COLUMN nbl_id SET DEFAULT nextval('natural_background_levels_nbl_id_seq'::regclass);


--
-- Name: nrm_id; Type: DEFAULT; Schema: public; Owner: -
--

ALTER TABLE ONLY norm ALTER COLUMN nrm_id SET DEFAULT nextval('norm_nrm_id_seq'::regclass);


--
-- Name: nmgp_id; Type: DEFAULT; Schema: public; Owner: -
--

ALTER TABLE ONLY norm_groep_type ALTER COLUMN nmgp_id SET DEFAULT nextval('norm_groep_type_nmgp_id_seq'::regclass);


--
-- Name: nhm_id; Type: DEFAULT; Schema: public; Owner: -
--

ALTER TABLE ONLY norm_hulp_mapping ALTER COLUMN nhm_id SET DEFAULT nextval('norm_hulp_mapping_nhm_id_seq'::regclass);


--
-- Name: nmkd_id; Type: DEFAULT; Schema: public; Owner: -
--

ALTER TABLE ONLY norm_kader_type ALTER COLUMN nmkd_id SET DEFAULT nextval('norm_kader_type_nmkd_id_seq'::regclass);


--
-- Name: nrmv_id; Type: DEFAULT; Schema: public; Owner: -
--

ALTER TABLE ONLY norm_value ALTER COLUMN nrmv_id SET DEFAULT nextval('norm_value_nrmv_id_seq'::regclass);


--
-- Name: nmpk_id; Type: DEFAULT; Schema: public; Owner: -
--

ALTER TABLE ONLY normpakket ALTER COLUMN nmpk_id SET DEFAULT nextval('normpakket_nmpk_id_seq'::regclass);


--
-- Name: ojg_id; Type: DEFAULT; Schema: public; Owner: -
--

ALTER TABLE ONLY object_group ALTER COLUMN ojg_id SET DEFAULT nextval('object_group_ojg_id_seq'::regclass);


--
-- Name: ost_id; Type: DEFAULT; Schema: public; Owner: -
--

ALTER TABLE ONLY object_state_column_required ALTER COLUMN ost_id SET DEFAULT nextval('object_state_column_required_ost_id_seq'::regclass);


--
-- Name: ost_id; Type: DEFAULT; Schema: public; Owner: -
--

ALTER TABLE ONLY object_state_type ALTER COLUMN ost_id SET DEFAULT nextval('object_state_type_ost_id_seq'::regclass);


--
-- Name: obj_id; Type: DEFAULT; Schema: public; Owner: -
--

ALTER TABLE ONLY object_type ALTER COLUMN obj_id SET DEFAULT nextval('object_type_obj_id_seq'::regclass);


--
-- Name: obex_id; Type: DEFAULT; Schema: public; Owner: -
--

ALTER TABLE ONLY objectives_exemption_type ALTER COLUMN obex_id SET DEFAULT nextval('objectives_exemption_type_obex_id_seq'::regclass);


--
-- Name: ocr_id; Type: DEFAULT; Schema: public; Owner: -
--

ALTER TABLE ONLY obs_ctx_role_type ALTER COLUMN ocr_id SET DEFAULT nextval('obs_ctx_role_type_ocr_id_seq'::regclass);


--
-- Name: obs_id; Type: DEFAULT; Schema: public; Owner: -
--

ALTER TABLE ONLY observation ALTER COLUMN obs_id SET DEFAULT nextval('observation_obs_id_seq'::regclass);


--
-- Name: role_id; Type: DEFAULT; Schema: public; Owner: -
--

ALTER TABLE ONLY observation_context ALTER COLUMN role_id SET DEFAULT nextval('observation_context_role_id_seq'::regclass);


--
-- Name: obp_id; Type: DEFAULT; Schema: public; Owner: -
--

ALTER TABLE ONLY observation_process_copy_dietmar ALTER COLUMN obp_id SET DEFAULT nextval('observation_process_copy_dietmar_obp_id_seq'::regclass);


--
-- Name: opt_id; Type: DEFAULT; Schema: public; Owner: -
--

ALTER TABLE ONLY observed_property_type ALTER COLUMN opt_id SET DEFAULT nextval('observed_property_type_opt_id_seq'::regclass);


--
-- Name: osc_id; Type: DEFAULT; Schema: public; Owner: -
--

ALTER TABLE ONLY observing_capability ALTER COLUMN osc_id SET DEFAULT nextval('observing_capability_osc_id_seq'::regclass);


--
-- Name: ocbs_id; Type: DEFAULT; Schema: public; Owner: -
--

ALTER TABLE ONLY observing_capability_observation ALTER COLUMN ocbs_id SET DEFAULT nextval('observing_capability_observation_ocbs_id_seq'::regclass);


--
-- Name: ocrp_id; Type: DEFAULT; Schema: public; Owner: -
--

ALTER TABLE ONLY observing_capability_responsible_party ALTER COLUMN ocrp_id SET DEFAULT nextval('observing_capability_responsible_party_ocrp_id_seq'::regclass);


--
-- Name: ocsa_id; Type: DEFAULT; Schema: public; Owner: -
--

ALTER TABLE ONLY observing_capability_sample ALTER COLUMN ocsa_id SET DEFAULT nextval('observing_capability_sample_ocsa_id_seq'::regclass);


--
-- Name: ocat_id; Type: DEFAULT; Schema: public; Owner: -
--

ALTER TABLE ONLY organisation_category_type ALTER COLUMN ocat_id SET DEFAULT nextval('organisation_category_type_ocat_id_seq'::regclass);


--
-- Name: ore_id; Type: DEFAULT; Schema: public; Owner: -
--

ALTER TABLE ONLY organisatorische_eenheid ALTER COLUMN ore_id SET DEFAULT nextval('organisatorische_eenheid_ore_id_seq'::regclass);


--
-- Name: organisatorische_eenheid_wkpusergroupid; Type: DEFAULT; Schema: public; Owner: -
--

ALTER TABLE ONLY organisatorische_eenheid_wkpusergroup ALTER COLUMN organisatorische_eenheid_wkpusergroupid SET DEFAULT nextval('organisatorische_eenheid_wkpu_organisatorische_eenheid_wkpu_seq'::regclass);


--
-- Name: obmb_id; Type: DEFAULT; Schema: public; Owner: -
--

ALTER TABLE ONLY other_basic_measure113b_type ALTER COLUMN obmb_id SET DEFAULT nextval('other_basic_measure113b_type_obmb_id_seq'::regclass);


--
-- Name: omut_id; Type: DEFAULT; Schema: public; Owner: -
--

ALTER TABLE ONLY other_monitoring_use_type ALTER COLUMN omut_id SET DEFAULT nextval('other_monitoring_use_type_omut_id_seq'::regclass);


--
-- Name: page_id; Type: DEFAULT; Schema: public; Owner: -
--

ALTER TABLE ONLY page ALTER COLUMN page_id SET DEFAULT nextval('page_page_id_seq'::regclass);


--
-- Name: pg_id; Type: DEFAULT; Schema: public; Owner: -
--

ALTER TABLE ONLY page_group ALTER COLUMN pg_id SET DEFAULT nextval('page_group_pg_id_seq'::regclass);


--
-- Name: pagepg_id; Type: DEFAULT; Schema: public; Owner: -
--

ALTER TABLE ONLY page_pagegroup ALTER COLUMN pagepg_id SET DEFAULT nextval('page_pagegroup_pagepg_id_seq'::regclass);


--
-- Name: prus_id; Type: DEFAULT; Schema: public; Owner: -
--

ALTER TABLE ONLY parameter_use_type ALTER COLUMN prus_id SET DEFAULT nextval('parameter_use_type_prus_id_seq'::regclass);


--
-- Name: pat_id; Type: DEFAULT; Schema: public; Owner: -
--

ALTER TABLE ONLY physical_alteration_type ALTER COLUMN pat_id SET DEFAULT nextval('physical_alteration_type_pat_id_seq'::regclass);


--
-- Name: pba_id; Type: DEFAULT; Schema: public; Owner: -
--

ALTER TABLE ONLY plaatsbepalingsapparaat_type ALTER COLUMN pba_id SET DEFAULT nextval('plaatsbepalingsapparaat_type_pba_id_seq'::regclass);


--
-- Name: pmf_id; Type: DEFAULT; Schema: public; Owner: -
--

ALTER TABLE ONLY planned_feature_monitoring ALTER COLUMN pmf_id SET DEFAULT nextval('planned_feature_monitoring_pmf_id_seq'::regclass);


--
-- Name: pltr_id; Type: DEFAULT; Schema: public; Owner: -
--

ALTER TABLE ONLY pollutant_trend ALTER COLUMN pltr_id SET DEFAULT nextval('pollutant_trend_pltr_id_seq'::regclass);


--
-- Name: pbm_id; Type: DEFAULT; Schema: public; Owner: -
--

ALTER TABLE ONLY pom_base_measure113a ALTER COLUMN pbm_id SET DEFAULT nextval('pom_base_measure113a_pbm_id_seq'::regclass);


--
-- Name: pcat_id; Type: DEFAULT; Schema: public; Owner: -
--

ALTER TABLE ONLY pressure_category_type ALTER COLUMN pcat_id SET DEFAULT nextval('pressure_category_type_pcat_id_seq'::regclass);


--
-- Name: prr_id; Type: DEFAULT; Schema: public; Owner: -
--

ALTER TABLE ONLY pressure_relevance_type ALTER COLUMN prr_id SET DEFAULT nextval('pressure_relevance_type_prr_id_seq'::regclass);


--
-- Name: prc_id; Type: DEFAULT; Schema: public; Owner: -
--

ALTER TABLE ONLY process_type ALTER COLUMN prc_id SET DEFAULT nextval('process_type_prc_id_seq'::regclass);


--
-- Name: profileid; Type: DEFAULT; Schema: public; Owner: -
--

ALTER TABLE ONLY profile ALTER COLUMN profileid SET DEFAULT nextval('profile_profileid_seq'::regclass);


--
-- Name: pmfp_id; Type: DEFAULT; Schema: public; Owner: -
--

ALTER TABLE ONLY projection ALTER COLUMN pmfp_id SET DEFAULT nextval('projection_pmfp_id_seq'::regclass);


--
-- Name: pat_id; Type: DEFAULT; Schema: public; Owner: -
--

ALTER TABLE ONLY protected_area_type ALTER COLUMN pat_id SET DEFAULT nextval('protected_area_type_pat_id_seq'::regclass);


--
-- Name: qeel_id; Type: DEFAULT; Schema: public; Owner: -
--

ALTER TABLE ONLY qe_ecological_type ALTER COLUMN qeel_id SET DEFAULT nextval('qe_ecological_type_qeel_id_seq'::regclass);


--
-- Name: qem_id; Type: DEFAULT; Schema: public; Owner: -
--

ALTER TABLE ONLY quality_element ALTER COLUMN qem_id SET DEFAULT nextval('quality_element_qem_id_seq'::regclass);


--
-- Name: qeo_id; Type: DEFAULT; Schema: public; Owner: -
--

ALTER TABLE ONLY quality_element_observation ALTER COLUMN qeo_id SET DEFAULT nextval('quality_element_observation_qeo_id_seq'::regclass);


--
-- Name: qes_id; Type: DEFAULT; Schema: public; Owner: -
--

ALTER TABLE ONLY quality_element_sample ALTER COLUMN qes_id SET DEFAULT nextval('quality_element_sample_qes_id_seq'::regclass);


--
-- Name: rct_id; Type: DEFAULT; Schema: public; Owner: -
--

ALTER TABLE ONLY reason_change_type ALTER COLUMN rct_id SET DEFAULT nextval('reason_change_type_rct_id_seq'::regclass);


--
-- Name: rsfr_id; Type: DEFAULT; Schema: public; Owner: -
--

ALTER TABLE ONLY rel_samp_feat_role_type ALTER COLUMN rsfr_id SET DEFAULT nextval('rel_samp_feat_role_type_rsfr_id_seq'::regclass);


--
-- Name: gwsw_id; Type: DEFAULT; Schema: public; Owner: -
--

ALTER TABLE ONLY relation_gwb_swb ALTER COLUMN gwsw_id SET DEFAULT nextval('relation_gwb_swb_gwsw_id_seq'::regclass);


--
-- Name: ore_wbd_id; Type: DEFAULT; Schema: public; Owner: -
--

ALTER TABLE ONLY relation_ore_wbd ALTER COLUMN ore_wbd_id SET DEFAULT nextval('relation_ore_wbd_ore_wbd_id_seq'::regclass);


--
-- Name: rlt_id; Type: DEFAULT; Schema: public; Owner: -
--

ALTER TABLE ONLY relation_type ALTER COLUMN rlt_id SET DEFAULT nextval('relation_type_rlt_id_seq'::regclass);


--
-- Name: rpv_id; Type: DEFAULT; Schema: public; Owner: -
--

ALTER TABLE ONLY report_version ALTER COLUMN rpv_id SET DEFAULT nextval('report_version_rpv_id_seq'::regclass);


--
-- Name: rpp_id; Type: DEFAULT; Schema: public; Owner: -
--

ALTER TABLE ONLY reporting_period ALTER COLUMN rpp_id SET DEFAULT nextval('reporting_period_rpp_id_seq'::regclass);


--
-- Name: ras_id; Type: DEFAULT; Schema: public; Owner: -
--

ALTER TABLE ONLY result_acquisition_source_type ALTER COLUMN ras_id SET DEFAULT nextval('result_acquisition_source_type_ras_id_seq'::regclass);


--
-- Name: rbmp_id; Type: DEFAULT; Schema: public; Owner: -
--

ALTER TABLE ONLY river_basin_management_plan ALTER COLUMN rbmp_id SET DEFAULT nextval('river_basin_management_plan_rbmp_id_seq'::regclass);


--
-- Name: roleid; Type: DEFAULT; Schema: public; Owner: -
--

ALTER TABLE ONLY role ALTER COLUMN roleid SET DEFAULT nextval('role_roleid_seq'::regclass);


--
-- Name: smp_id; Type: DEFAULT; Schema: public; Owner: -
--

ALTER TABLE ONLY sampling_proces ALTER COLUMN smp_id SET DEFAULT nextval('sampling_proces_smp_id_seq'::regclass);


--
-- Name: semf_id; Type: DEFAULT; Schema: public; Owner: -
--

ALTER TABLE ONLY specialised_emf_type ALTER COLUMN semf_id SET DEFAULT nextval('specialised_emf_type_semf_id_seq'::regclass);


--
-- Name: slt_id; Type: DEFAULT; Schema: public; Owner: -
--

ALTER TABLE ONLY station_level_type ALTER COLUMN slt_id SET DEFAULT nextval('station_level_type_slt_id_seq'::regclass);


--
-- Name: stt_id; Type: DEFAULT; Schema: public; Owner: -
--

ALTER TABLE ONLY station_type_type ALTER COLUMN stt_id SET DEFAULT nextval('station_type_type_stt_id_seq'::regclass);


--
-- Name: sst_id; Type: DEFAULT; Schema: public; Owner: -
--

ALTER TABLE ONLY subsite_type ALTER COLUMN sst_id SET DEFAULT nextval('subsite_type_sst_id_seq'::regclass);


--
-- Name: ssg_id; Type: DEFAULT; Schema: public; Owner: -
--

ALTER TABLE ONLY substance_group ALTER COLUMN ssg_id SET DEFAULT nextval('substance_group_ssg_id_seq'::regclass);


--
-- Name: sasp_id; Type: DEFAULT; Schema: public; Owner: -
--

ALTER TABLE ONLY sw_abstraction_point ALTER COLUMN sasp_id SET DEFAULT nextval('sw_abstracion_point_sasp_id_seq'::regclass);


--
-- Name: swap_id; Type: DEFAULT; Schema: public; Owner: -
--

ALTER TABLE ONLY sw_aggregated_pressure_type ALTER COLUMN swap_id SET DEFAULT nextval('sw_aggregated_pressure_type_swap_id_seq'::regclass);


--
-- Name: swc_id; Type: DEFAULT; Schema: public; Owner: -
--

ALTER TABLE ONLY sw_category_type ALTER COLUMN swc_id SET DEFAULT nextval('sw_category_type_swc_id_seq'::regclass);


--
-- Name: css_id; Type: DEFAULT; Schema: public; Owner: -
--

ALTER TABLE ONLY sw_chemical_substance_status ALTER COLUMN css_id SET DEFAULT nextval('sw_chemical_substance_status_css_id_seq'::regclass);


--
-- Name: ecs_id; Type: DEFAULT; Schema: public; Owner: -
--

ALTER TABLE ONLY sw_ecological_status ALTER COLUMN ecs_id SET DEFAULT nextval('sw_ecological_status_ecs_id_seq'::regclass);


--
-- Name: sprm_id; Type: DEFAULT; Schema: public; Owner: -
--

ALTER TABLE ONLY sw_pressure_requiring_supp_add_measures ALTER COLUMN sprm_id SET DEFAULT nextval('sw_pressure_requiring_supp_add_measures_sprm_id_seq'::regclass);


--
-- Name: sprs_id; Type: DEFAULT; Schema: public; Owner: -
--

ALTER TABLE ONLY sw_pressure_type ALTER COLUMN sprs_id SET DEFAULT nextval('sw_pressure_type_sprs_id_seq'::regclass);


--
-- Name: spg_id; Type: DEFAULT; Schema: public; Owner: -
--

ALTER TABLE ONLY sw_pressures_preventing_good_status ALTER COLUMN spg_id SET DEFAULT nextval('sw_pressures_preventing_good_status_spg_id_seq'::regclass);


--
-- Name: smeu_id; Type: DEFAULT; Schema: public; Owner: -
--

ALTER TABLE ONLY sw_supp_measure_eu_type ALTER COLUMN smeu_id SET DEFAULT nextval('sw_supp_measure_eu_type_smeu_id_seq'::regclass);


--
-- Name: styp_id; Type: DEFAULT; Schema: public; Owner: -
--

ALTER TABLE ONLY sw_typology_type ALTER COLUMN styp_id SET DEFAULT nextval('sw_typology_type_styp_id_seq'::regclass);


--
-- Name: swce_id; Type: DEFAULT; Schema: public; Owner: -
--

ALTER TABLE ONLY swb_exemption ALTER COLUMN swce_id SET DEFAULT nextval('swb_chemical_exemption_swce_id_seq'::regclass);


--
-- Name: swee_id; Type: DEFAULT; Schema: public; Owner: -
--

ALTER TABLE ONLY swb_measures_43a ALTER COLUMN swee_id SET DEFAULT nextval('swb_ecological_exemption_swee_id_seq'::regclass);


--
-- Name: sys_id; Type: DEFAULT; Schema: public; Owner: -
--

ALTER TABLE ONLY swb_yearly_status ALTER COLUMN sys_id SET DEFAULT nextval('swb_yearly_status_sys_id_seq'::regclass);


--
-- Name: sc_id; Type: DEFAULT; Schema: public; Owner: -
--

ALTER TABLE ONLY system_configuration ALTER COLUMN sc_id SET DEFAULT nextval('system_configuration_sc_id_seq'::regclass);


--
-- Name: txg_id; Type: DEFAULT; Schema: public; Owner: -
--

ALTER TABLE ONLY taxa_group ALTER COLUMN txg_id SET DEFAULT nextval('taxa_group_txg_id_seq'::regclass);


--
-- Name: txn_id; Type: DEFAULT; Schema: public; Owner: -
--

ALTER TABLE ONLY taxon_type ALTER COLUMN txn_id SET DEFAULT nextval('taxon_type_txn_id_seq'::regclass);


--
-- Name: taov_id; Type: DEFAULT; Schema: public; Owner: -
--

ALTER TABLE ONLY thema_actie_organisatorische_eenheid_voortgang ALTER COLUMN taov_id SET DEFAULT nextval('thema_actie_organisatorische_eenheid_voortgang_taov_id_seq'::regclass);


--
-- Name: ta_id; Type: DEFAULT; Schema: public; Owner: -
--

ALTER TABLE ONLY thema_acties ALTER COLUMN ta_id SET DEFAULT nextval('thema_acties_ta_id_seq'::regclass);


--
-- Name: tog_id; Type: DEFAULT; Schema: public; Owner: -
--

ALTER TABLE ONLY thema_overzicht_groepen ALTER COLUMN tog_id SET DEFAULT nextval('thema_overzicht_groepen_tog_id_seq'::regclass);


--
-- Name: tos_id; Type: DEFAULT; Schema: public; Owner: -
--

ALTER TABLE ONLY thema_overzicht_statussen ALTER COLUMN tos_id SET DEFAULT nextval('thema_overzicht_statussen_tos_id_seq'::regclass);


--
-- Name: t_id; Type: DEFAULT; Schema: public; Owner: -
--

ALTER TABLE ONLY themas ALTER COLUMN t_id SET DEFAULT nextval('themas_t_id_seq'::regclass);


--
-- Name: transformationid; Type: DEFAULT; Schema: public; Owner: -
--

ALTER TABLE ONLY transformation ALTER COLUMN transformationid SET DEFAULT nextval('transformation_transformationid_seq'::regclass);


--
-- Name: typ_id; Type: DEFAULT; Schema: public; Owner: -
--

ALTER TABLE ONLY typering_type ALTER COLUMN typ_id SET DEFAULT nextval('typering_type_typ_id_seq'::regclass);


--
-- Name: validationid; Type: DEFAULT; Schema: public; Owner: -
--

ALTER TABLE ONLY validation ALTER COLUMN validationid SET DEFAULT nextval('validation_validationid_seq'::regclass);


--
-- Name: validation_importtypeid; Type: DEFAULT; Schema: public; Owner: -
--

ALTER TABLE ONLY validation_importtype ALTER COLUMN validation_importtypeid SET DEFAULT nextval('validation_importtype_validation_importtypeid_seq'::regclass);


--
-- Name: vst_id; Type: DEFAULT; Schema: public; Owner: -
--

ALTER TABLE ONLY volumestroom_type ALTER COLUMN vst_id SET DEFAULT nextval('volumestroom_type_vst_id_seq'::regclass);


--
-- Name: vtb_id; Type: DEFAULT; Schema: public; Owner: -
--

ALTER TABLE ONLY volumestroom_type_bronnen ALTER COLUMN vtb_id SET DEFAULT nextval('volumestroom_type_bronnen_vtb_id_seq'::regclass);


--
-- Name: wbpm_id; Type: DEFAULT; Schema: public; Owner: -
--

ALTER TABLE ONLY waarde_bepalings_methode_type ALTER COLUMN wbpm_id SET DEFAULT nextval('waarde_bepalings_methode_type_wbpm_id_seq'::regclass);


--
-- Name: wbm_id; Type: DEFAULT; Schema: public; Owner: -
--

ALTER TABLE ONLY waarde_bewerkings_methode_type ALTER COLUMN wbm_id SET DEFAULT nextval('waarde_bewerkings_methode_type_wbm_id_seq'::regclass);


--
-- Name: wbpa_id; Type: DEFAULT; Schema: public; Owner: -
--

ALTER TABLE ONLY waterbody_protected_area_intersection ALTER COLUMN wbpa_id SET DEFAULT nextval('waterbody_protected_area_intersection_wbpa_id_seq'::regclass);


--
-- Name: wbpr_id; Type: DEFAULT; Schema: public; Owner: -
--

ALTER TABLE ONLY wb_prognosis ALTER COLUMN wbpr_id SET DEFAULT nextval('swb_prognosis_swpr_id_seq'::regclass);


--
-- Name: wbsc_id; Type: DEFAULT; Schema: public; Owner: -
--

ALTER TABLE ONLY wb_status_change_motivation ALTER COLUMN wbsc_id SET DEFAULT nextval('wb_status_change_motivation_wbsc_id_seq'::regclass);


--
-- Name: qegw_id; Type: DEFAULT; Schema: public; Owner: -
--

ALTER TABLE ONLY wfd_qe_gwtype ALTER COLUMN qegw_id SET DEFAULT nextval('wfd_qe_gwtype_qegw_id_seq'::regclass);


--
-- Name: qesw_id; Type: DEFAULT; Schema: public; Owner: -
--

ALTER TABLE ONLY wfd_qe_swtype ALTER COLUMN qesw_id SET DEFAULT nextval('wfd_qe_swtype_qesw_id_seq'::regclass);


--
-- Name: wsc_id; Type: DEFAULT; Schema: public; Owner: -
--

ALTER TABLE ONLY wfd_status_code ALTER COLUMN wsc_id SET DEFAULT nextval('wfd_status_code_wsc_id_seq'::regclass);


--
-- Name: wkpuserid; Type: DEFAULT; Schema: public; Owner: -
--

ALTER TABLE ONLY wkpuser ALTER COLUMN wkpuserid SET DEFAULT nextval('wkpuser_wkpuserid_seq'::regclass);


--
-- Name: wkpuser_importtypeid; Type: DEFAULT; Schema: public; Owner: -
--

ALTER TABLE ONLY wkpuser_importtype ALTER COLUMN wkpuser_importtypeid SET DEFAULT nextval('wkpuser_importtype_wkpuser_importtypeid_seq'::regclass);


--
-- Name: wupg_id; Type: DEFAULT; Schema: public; Owner: -
--

ALTER TABLE ONLY wkpuser_pagegroup ALTER COLUMN wupg_id SET DEFAULT nextval('wkpuser_pagegroup_wupg_id_seq'::regclass);


--
-- Name: wkpuser_wkpusergroup_id; Type: DEFAULT; Schema: public; Owner: -
--

ALTER TABLE ONLY wkpuser_wkpusergroup ALTER COLUMN wkpuser_wkpusergroup_id SET DEFAULT nextval('wkpuser_wkpusergroup_wkpuser_wkpusergroup_id_seq'::regclass);


--
-- Name: wkpusergroupid; Type: DEFAULT; Schema: public; Owner: -
--

ALTER TABLE ONLY wkpusergroup ALTER COLUMN wkpusergroupid SET DEFAULT nextval('wkpusergroup_wkpusergroupid_seq'::regclass);


--
-- Name: wkpuserinroleid; Type: DEFAULT; Schema: public; Owner: -
--

ALTER TABLE ONLY wkpuserinrole ALTER COLUMN wkpuserinroleid SET DEFAULT nextval('wkpuserinrole_wkpuserinroleid_seq'::regclass);


--
-- Name: wkrv_id; Type: DEFAULT; Schema: public; Owner: -
--

ALTER TABLE ONLY wkr_version ALTER COLUMN wkrv_id SET DEFAULT nextval('wkr_version_wkrv_id_seq'::regclass);


--
-- Name: ynna_id; Type: DEFAULT; Schema: public; Owner: -
--

ALTER TABLE ONLY yes_no_not_applicable_type ALTER COLUMN ynna_id SET DEFAULT nextval('yes_no_not_applicable_type_ynna_id_seq'::regclass);


--
-- Name: ztc_id; Type: DEFAULT; Schema: public; Owner: -
--

ALTER TABLE ONLY zone_type_code ALTER COLUMN ztc_id SET DEFAULT nextval('zone_type_code_ztc_id_seq'::regclass);



--
-- Name: stat_user_tables_hist_pkey; Type: CONSTRAINT; Schema: beheer; Owner: -
--

ALTER TABLE ONLY stat_user_tables_hist
    ADD CONSTRAINT stat_user_tables_hist_pkey PRIMARY KEY (suth_id);



--
-- Name: UK_idd_name; Type: CONSTRAINT; Schema: domains; Owner: -
--

ALTER TABLE ONLY indicator_descriptor
    ADD CONSTRAINT "UK_idd_name" UNIQUE (name);


--
-- Name: UQ_clt_code; Type: CONSTRAINT; Schema: domains; Owner: -
--

ALTER TABLE ONLY confidence_level_type
    ADD CONSTRAINT "UQ_clt_code" UNIQUE (code);


--
-- Name: UQ_ctf_code; Type: CONSTRAINT; Schema: domains; Owner: -
--

ALTER TABLE ONLY certificeringscode
    ADD CONSTRAINT "UQ_ctf_code" UNIQUE (code);


--
-- Name: UQ_ltwb_code; Type: CONSTRAINT; Schema: domains; Owner: -
--

ALTER TABLE ONLY locatietype_waardebepaling
    ADD CONSTRAINT "UQ_ltwb_code" UNIQUE (code);


--
-- Name: UQ_mar_code; Type: CONSTRAINT; Schema: domains; Owner: -
--

ALTER TABLE ONLY meetapparaat
    ADD CONSTRAINT "UQ_mar_code" UNIQUE (code);


--
-- Name: UQ_mbm_code; Type: CONSTRAINT; Schema: domains; Owner: -
--

ALTER TABLE ONLY monsterbewerkingsmethode
    ADD CONSTRAINT "UQ_mbm_code" UNIQUE (code);


--
-- Name: UQ_mvb_code; Type: CONSTRAINT; Schema: domains; Owner: -
--

ALTER TABLE ONLY monstervoorbehandeling
    ADD CONSTRAINT "UQ_mvb_code" UNIQUE (code);


--
-- Name: UQ_scm_description; Type: CONSTRAINT; Schema: domains; Owner: -
--

ALTER TABLE ONLY status_change_motivation_type
    ADD CONSTRAINT "UQ_scm_description" UNIQUE (description);


--
-- Name: UQ_wbpt_code; Type: CONSTRAINT; Schema: domains; Owner: -
--

ALTER TABLE ONLY waardebepalingstechniek
    ADD CONSTRAINT "UQ_wbpt_code" UNIQUE (code);


--
-- Name: pk_bmm; Type: CONSTRAINT; Schema: domains; Owner: -
--

ALTER TABLE ONLY bemonsteringsmethode
    ADD CONSTRAINT pk_bmm PRIMARY KEY (bmm_id);


--
-- Name: pk_clt; Type: CONSTRAINT; Schema: domains; Owner: -
--

ALTER TABLE ONLY confidence_level_type
    ADD CONSTRAINT pk_clt PRIMARY KEY (clt_id);


--
-- Name: pk_ctf; Type: CONSTRAINT; Schema: domains; Owner: -
--

ALTER TABLE ONLY certificeringscode
    ADD CONSTRAINT pk_ctf PRIMARY KEY (ctf_id);


--
-- Name: pk_driver_id; Type: CONSTRAINT; Schema: domains; Owner: -
--

ALTER TABLE ONLY drivers
    ADD CONSTRAINT pk_driver_id PRIMARY KEY (driver_id);


--
-- Name: pk_idd; Type: CONSTRAINT; Schema: domains; Owner: -
--

ALTER TABLE ONLY indicator_descriptor
    ADD CONSTRAINT pk_idd PRIMARY KEY (idd_id);


--
-- Name: pk_impact_id; Type: CONSTRAINT; Schema: domains; Owner: -
--

ALTER TABLE ONLY impacts
    ADD CONSTRAINT pk_impact_id PRIMARY KEY (impact_id);


--
-- Name: pk_ltwb; Type: CONSTRAINT; Schema: domains; Owner: -
--

ALTER TABLE ONLY locatietype_waardebepaling
    ADD CONSTRAINT pk_ltwb PRIMARY KEY (ltwb_id);


--
-- Name: pk_mar; Type: CONSTRAINT; Schema: domains; Owner: -
--

ALTER TABLE ONLY meetapparaat
    ADD CONSTRAINT pk_mar PRIMARY KEY (mar_id);


--
-- Name: pk_mbm; Type: CONSTRAINT; Schema: domains; Owner: -
--

ALTER TABLE ONLY monsterbewerkingsmethode
    ADD CONSTRAINT pk_mbm PRIMARY KEY (mbm_id);


--
-- Name: pk_mvb; Type: CONSTRAINT; Schema: domains; Owner: -
--

ALTER TABLE ONLY monstervoorbehandeling
    ADD CONSTRAINT pk_mvb PRIMARY KEY (mvb_id);


--
-- Name: pk_orgaan; Type: CONSTRAINT; Schema: domains; Owner: -
--

ALTER TABLE ONLY orgaan
    ADD CONSTRAINT pk_orgaan PRIMARY KEY (org_id);


--
-- Name: pk_scm; Type: CONSTRAINT; Schema: domains; Owner: -
--

ALTER TABLE ONLY status_change_motivation_type
    ADD CONSTRAINT pk_scm PRIMARY KEY (scm_id);


--
-- Name: pk_var; Type: CONSTRAINT; Schema: domains; Owner: -
--

ALTER TABLE ONLY veldapparaat
    ADD CONSTRAINT pk_var PRIMARY KEY (var_id);


--
-- Name: pk_wbpt; Type: CONSTRAINT; Schema: domains; Owner: -
--

ALTER TABLE ONLY waardebepalingstechniek
    ADD CONSTRAINT pk_wbpt PRIMARY KEY (wbpt_id);


--
-- Name: uq_opt_id; Type: CONSTRAINT; Schema: domains; Owner: -
--

ALTER TABLE ONLY indicator_descriptor
    ADD CONSTRAINT uq_opt_id UNIQUE (opt_id, part_of_idd_id);



--
-- Name: pk_monprog; Type: CONSTRAINT; Schema: eu_state_of_environment; Owner: -
--

ALTER TABLE ONLY monprog_2015
    ADD CONSTRAINT pk_monprog PRIMARY KEY (mpnident, parameter, monsoort, repr_owm);



--
-- Name: rapport_tekst_id_pk; Type: CONSTRAINT; Schema: factsheets; Owner: -
--

ALTER TABLE ONLY rapport_tekst
    ADD CONSTRAINT rapport_tekst_id_pk PRIMARY KEY (rapport_tekst_id);


--
-- Name: uitvoering_type_id_pk; Type: CONSTRAINT; Schema: factsheets; Owner: -
--

ALTER TABLE ONLY uitvoering_type
    ADD CONSTRAINT uitvoering_type_id_pk PRIMARY KEY (uitvoering_type_id);


--
-- Name: veld_id_pk; Type: CONSTRAINT; Schema: factsheets; Owner: -
--

ALTER TABLE ONLY veld
    ADD CONSTRAINT veld_id_pk PRIMARY KEY (veld_id);


--
-- Name: wb_type_id_pk; Type: CONSTRAINT; Schema: factsheets; Owner: -
--

ALTER TABLE ONLY wb_type
    ADD CONSTRAINT wb_type_id_pk PRIMARY KEY (wb_type_id);



--
-- Name: pk_idd; Type: CONSTRAINT; Schema: krm; Owner: -
--

ALTER TABLE ONLY cycle_description
    ADD CONSTRAINT pk_idd PRIMARY KEY (cym_id);



--
-- Name: pk_pot; Type: CONSTRAINT; Schema: monprog; Owner: -
--

ALTER TABLE ONLY planned_observation_time
    ADD CONSTRAINT pk_pot PRIMARY KEY (pot_id);


--
-- Name: pk_qem_idd; Type: CONSTRAINT; Schema: monprog; Owner: -
--

ALTER TABLE ONLY quality_element_indicator_descriptor
    ADD CONSTRAINT pk_qem_idd PRIMARY KEY (qem_id, idd_id);



--
-- Name: PK_Actie; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY "Actie"
    ADD CONSTRAINT "PK_Actie" PRIMARY KEY (id);


--
-- Name: PK_VerwerkingsVerslag; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY "VerwerkingsVerslag"
    ADD CONSTRAINT "PK_VerwerkingsVerslag" PRIMARY KEY (id);


--
-- Name: PK_VerwerkingsVerslagParameter; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY "VerwerkingsVerslagParameter"
    ADD CONSTRAINT "PK_VerwerkingsVerslagParameter" PRIMARY KEY (id);


--
-- Name: PK_VerwerkingsVerslagRegel; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY "VerwerkingsVerslagRegel"
    ADD CONSTRAINT "PK_VerwerkingsVerslagRegel" PRIMARY KEY (id);


--
-- Name: PK_VerwerkingsVerslagRegelSoort; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY "VerwerkingsVerslagRegelSoort"
    ADD CONSTRAINT "PK_VerwerkingsVerslagRegelSoort" PRIMARY KEY (id);


--
-- Name: PK_VerwerkingsVerslagStatus; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY "VerwerkingsVerslagStatus"
    ADD CONSTRAINT "PK_VerwerkingsVerslagStatus" PRIMARY KEY (id);


--
-- Name: UQ_wbsc; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY wb_status_change_motivation
    ADD CONSTRAINT "UQ_wbsc" UNIQUE (wbd_id, scm_id, opt_id, year_initial, year_status);


--
-- Name: _hab_ds_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY _hab_ds
    ADD CONSTRAINT _hab_ds_pkey PRIMARY KEY (id);


--
-- Name: _vog_ds_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY _vog_ds
    ADD CONSTRAINT _vog_ds_pkey PRIMARY KEY (id);


--
-- Name: application_applicationname_key; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY application
    ADD CONSTRAINT application_applicationname_key UNIQUE (applicationname);


--
-- Name: application_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY application
    ADD CONSTRAINT application_pkey PRIMARY KEY (applicationid);


--
-- Name: bronnen_id_vst_id; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY volumestroom_type_bronnen
    ADD CONSTRAINT bronnen_id_vst_id UNIQUE (bronnen_id, vst_id);


--
-- Name: csvtranformation_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY csvtransformation
    ADD CONSTRAINT csvtranformation_pkey PRIMARY KEY (csvtransformationid);


--
-- Name: importrule_name_key; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY importrule
    ADD CONSTRAINT importrule_name_key UNIQUE (name);


--
-- Name: importrule_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY importrule
    ADD CONSTRAINT importrule_pkey PRIMARY KEY (importruleid);


--
-- Name: importtype_name_key; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY importtype
    ADD CONSTRAINT importtype_name_key UNIQUE (name);


--
-- Name: importtype_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY importtype
    ADD CONSTRAINT importtype_pkey PRIMARY KEY (importtypeid);


--
-- Name: logging_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY logging
    ADD CONSTRAINT logging_pkey PRIMARY KEY (loggingid);


--
-- Name: map_ref; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY kaarten_sgbp
    ADD CONSTRAINT map_ref UNIQUE (map_ref);


--
-- Name: membership_application_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY membership
    ADD CONSTRAINT membership_application_pkey PRIMARY KEY (wkpuserid, applicationid);


--
-- Name: moqe_pk; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY monitoring_object_quality_element
    ADD CONSTRAINT moqe_pk PRIMARY KEY (moqe_id);


--
-- Name: ore_id_wbd_id; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY relation_ore_wbd
    ADD CONSTRAINT ore_id_wbd_id UNIQUE (ore_id, wbd_id);


--
-- Name: page_id_pg_id; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY page_pagegroup
    ADD CONSTRAINT page_id_pg_id UNIQUE (pg_id, page_id);


--
-- Name: pg_id_wkpuserid; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY wkpuser_pagegroup
    ADD CONSTRAINT pg_id_wkpuserid UNIQUE (pg_id, wkpuserid);


--
-- Name: pk_abstraction_point; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY abstraction_point
    ADD CONSTRAINT pk_abstraction_point PRIMARY KEY (asp_id);


--
-- Name: pk_activity_organisation_category; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY activity_organisation_category
    ADD CONSTRAINT pk_activity_organisation_category PRIMARY KEY (isac_id, ocat_id);


--
-- Name: pk_akvoi; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY aquo_kit_voor_opt_id
    ADD CONSTRAINT pk_akvoi UNIQUE (grootheid_code, biotaxon_aquo, hoedanigheid_code, taxa_group_name, type_stof);


--
-- Name: pk_any_thematic_link; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY any_thematic_link
    ADD CONSTRAINT pk_any_thematic_link PRIMARY KEY (atl_id);


--
-- Name: pk_art43b_type; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY eu_article_43b_type
    ADD CONSTRAINT pk_art43b_type PRIMARY KEY (a43b_id);


--
-- Name: pk_asp; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY measure_per_abstraction_point
    ADD CONSTRAINT pk_asp PRIMARY KEY (mtm_id, asp_id);


--
-- Name: pk_asps; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY gw_abstraction_point_status
    ADD CONSTRAINT pk_asps PRIMARY KEY (asp_id, gwsy_id);


--
-- Name: pk_bio_observation; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY bio_observation
    ADD CONSTRAINT pk_bio_observation PRIMARY KEY (obs_id);


--
-- Name: pk_bma; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY basic_measure113a_type
    ADD CONSTRAINT pk_bma PRIMARY KEY (bma_id);


--
-- Name: pk_bpg; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY bepaling_grens_type
    ADD CONSTRAINT pk_bpg PRIMARY KEY (bpg_id);


--
-- Name: pk_bronnen; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY bronnen
    ADD CONSTRAINT pk_bronnen PRIMARY KEY (bronnen_id);


--
-- Name: pk_ca_role_code; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY ca_role_code
    ADD CONSTRAINT pk_ca_role_code PRIMARY KEY (crc_id);


--
-- Name: pk_chemical_exceedance; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY chemical_exceedance
    ADD CONSTRAINT pk_chemical_exceedance PRIMARY KEY (sys_id, chs_id);


--
-- Name: pk_chemische_stof_type; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY chemische_stof_type
    ADD CONSTRAINT pk_chemische_stof_type PRIMARY KEY (chs_id);


--
-- Name: pk_classificatie_type; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY classification_type
    ADD CONSTRAINT pk_classificatie_type PRIMARY KEY (cls_id);


--
-- Name: pk_clsg; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY classification_group_type
    ADD CONSTRAINT pk_clsg PRIMARY KEY (clsg_id);


--
-- Name: pk_competent_authority; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY competent_authority
    ADD CONSTRAINT pk_competent_authority PRIMARY KEY (ore_id);


--
-- Name: pk_competent_authority_roles_guid; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY competent_authority_roles
    ADD CONSTRAINT pk_competent_authority_roles_guid PRIMARY KEY (guid);


--
-- Name: pk_competentauthority_namespacetype; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY competentauthority_namespacetype
    ADD CONSTRAINT pk_competentauthority_namespacetype PRIMARY KEY (ns_id, ore_id);


--
-- Name: pk_condition_of_gw_type; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY condition_of_gw_type
    ADD CONSTRAINT pk_condition_of_gw_type PRIMARY KEY (cog_id);


--
-- Name: pk_cptm; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY compartiment_type
    ADD CONSTRAINT pk_cptm PRIMARY KEY (cptm_id);


--
-- Name: pk_depth_range_type; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY depth_range_type
    ADD CONSTRAINT pk_depth_range_type PRIMARY KEY (dpr_id);


--
-- Name: pk_domeintable_changes_id; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY domaintable_changes
    ADD CONSTRAINT pk_domeintable_changes_id PRIMARY KEY (domaintable_changes_id);


--
-- Name: pk_eenheid_type; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY eenheid_type
    ADD CONSTRAINT pk_eenheid_type PRIMARY KEY (eenh_id);


--
-- Name: pk_emf; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY environmental_monitoring_facility
    ADD CONSTRAINT pk_emf PRIMARY KEY (emf_id);


--
-- Name: pk_emn; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY environmental_monitoring_network
    ADD CONSTRAINT pk_emn PRIMARY KEY (emn_id);


--
-- Name: pk_eu_depth_level_type; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY eu_depth_level_type
    ADD CONSTRAINT pk_eu_depth_level_type PRIMARY KEY (dlt_id);


--
-- Name: pk_eu_intercalibration_type; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY eu_intercalibration_type
    ADD CONSTRAINT pk_eu_intercalibration_type PRIMARY KEY (icalt);


--
-- Name: pk_eu_monitoring_goal; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY eu_monitoring_goal_type
    ADD CONSTRAINT pk_eu_monitoring_goal PRIMARY KEY (eumg_id);


--
-- Name: pk_eu_monitoring_type; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY eu_monitoring_type
    ADD CONSTRAINT pk_eu_monitoring_type PRIMARY KEY (mtt_id);


--
-- Name: pk_eu_nl_code_to_sitecode; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY eu_nl_code_to_sitecode
    ADD CONSTRAINT pk_eu_nl_code_to_sitecode PRIMARY KEY (nts_id);


--
-- Name: pk_euf; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY eu_fund_type
    ADD CONSTRAINT pk_euf PRIMARY KEY (euf_id);


--
-- Name: pk_excemption_mechanism; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY swb_excemption_mechanism_44
    ADD CONSTRAINT pk_excemption_mechanism PRIMARY KEY (swce_id, exme_id);


--
-- Name: pk_exme; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY excemption_mechanism_type
    ADD CONSTRAINT pk_exme PRIMARY KEY (exme_id);


--
-- Name: pk_faq_item_id; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY faq_item
    ADD CONSTRAINT pk_faq_item_id PRIMARY KEY (faq_item_id);


--
-- Name: pk_faq_thema_id; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY faq_thema
    ADD CONSTRAINT pk_faq_thema_id PRIMARY KEY (faq_thema_id);


--
-- Name: pk_fim; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY env_mon_facil_in_mngmt_reg_or_restr_zone
    ADD CONSTRAINT pk_fim PRIMARY KEY (emf_id, mrz_id);


--
-- Name: pk_fu43_id; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY eu_function_43a_type
    ADD CONSTRAINT pk_fu43_id PRIMARY KEY (fu43_id);


--
-- Name: pk_generatefactsheet_id; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY generatedfactsheets
    ADD CONSTRAINT pk_generatefactsheet_id PRIMARY KEY (id);


--
-- Name: pk_geo_reference_process; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY obs_process_meetapparaat
    ADD CONSTRAINT pk_geo_reference_process PRIMARY KEY (obp_id, mar_id);


--
-- Name: pk_geological_formation_type; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY geological_formation_type
    ADD CONSTRAINT pk_geological_formation_type PRIMARY KEY (gfm_id);


--
-- Name: pk_gn2kcs; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY gw_n2000_status
    ADD CONSTRAINT pk_gn2kcs PRIMARY KEY (wpa_id, gwsy, opt_id);


--
-- Name: pk_gr; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY legislation_reference_type
    ADD CONSTRAINT pk_gr PRIMARY KEY (lgr_id);


--
-- Name: pk_grcf; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY gw_reason4chemical_failure
    ADD CONSTRAINT pk_grcf PRIMARY KEY (grcf_id);


--
-- Name: pk_grh; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY grootheid_type
    ADD CONSTRAINT pk_grh PRIMARY KEY (grh_id);


--
-- Name: pk_grqf; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY gw_reason4quantity_failure
    ADD CONSTRAINT pk_grqf PRIMARY KEY (grqf_id);


--
-- Name: pk_gtcc_gys_obs; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY gw_testing_conclusion
    ADD CONSTRAINT pk_gtcc_gys_obs PRIMARY KEY (gtcc_id, gys_id, eumg_id);


--
-- Name: pk_gw_abstraction_point; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY gw_abstraction_point
    ADD CONSTRAINT pk_gw_abstraction_point PRIMARY KEY (gasp_id);


--
-- Name: pk_gw_aggregated_pressure_type; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY gw_aggregated_pressure_type
    ADD CONSTRAINT pk_gw_aggregated_pressure_type PRIMARY KEY (gwap_id);


--
-- Name: pk_gw_mon_stat_other_mon_use; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY gw_mon_stat_other_mon_use
    ADD CONSTRAINT pk_gw_mon_stat_other_mon_use PRIMARY KEY (gms_id, omut_id);


--
-- Name: pk_gw_monitoring_station; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY gw_monitoring_station
    ADD CONSTRAINT pk_gw_monitoring_station PRIMARY KEY (gms_id);


--
-- Name: pk_gw_pollutants; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY gw_pollutants
    ADD CONSTRAINT pk_gw_pollutants PRIMARY KEY (gys_id, chs_id);


--
-- Name: pk_gw_pressure_requiring_supp_add_measures; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY gw_pressure_requiring_supp_add_measures
    ADD CONSTRAINT pk_gw_pressure_requiring_supp_add_measures PRIMARY KEY (gprm_id);


--
-- Name: pk_gw_pressure_type; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY gw_pressure_type
    ADD CONSTRAINT pk_gw_pressure_type PRIMARY KEY (gprs_id);


--
-- Name: pk_gw_pressure_type_driver_ids; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY gw_pressure_type_driver
    ADD CONSTRAINT pk_gw_pressure_type_driver_ids PRIMARY KEY (gprs_id, driver_id);


--
-- Name: pk_gw_pressures_preventing_good_status; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY gw_pressures_preventing_good_status
    ADD CONSTRAINT pk_gw_pressures_preventing_good_status PRIMARY KEY (gpg_id);


--
-- Name: pk_gw_required_supp_measure; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY gw_required_supp_measure
    ADD CONSTRAINT pk_gw_required_supp_measure PRIMARY KEY (gprm_id, smnl_id);


--
-- Name: pk_gw_test_value; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY gw_test_value
    ADD CONSTRAINT pk_gw_test_value PRIMARY KEY (gtcc_id, nrmv_id);


--
-- Name: pk_gw_vertical_orientation_type; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY gw_vertical_orientation_type
    ADD CONSTRAINT pk_gw_vertical_orientation_type PRIMARY KEY (gvo_id);


--
-- Name: pk_gwb_chem_exemp_pollutant; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY gwb_chem_exemp_pollutant
    ADD CONSTRAINT pk_gwb_chem_exemp_pollutant PRIMARY KEY (gwce_id, opt_id);


--
-- Name: pk_gwb_chemical_exemption; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY gwb_chemical_exemption
    ADD CONSTRAINT pk_gwb_chemical_exemption PRIMARY KEY (gwce_id);


--
-- Name: pk_gwb_conceptual_model; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY gwb_conceptual_model
    ADD CONSTRAINT pk_gwb_conceptual_model PRIMARY KEY (gcm_id);


--
-- Name: pk_gwb_pressure; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY gwb_pressure
    ADD CONSTRAINT pk_gwb_pressure PRIMARY KEY (gwbp_id);


--
-- Name: pk_gwb_pressure_impact_ids; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY gwb_pressure_impact
    ADD CONSTRAINT pk_gwb_pressure_impact_ids PRIMARY KEY (gwbp_id, impact_id);


--
-- Name: pk_gwb_quantitative_exemption; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY gwb_quantitative_exemption
    ADD CONSTRAINT pk_gwb_quantitative_exemption PRIMARY KEY (gqe_id);


--
-- Name: pk_gwb_yearly_status; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY gwb_yearly_status
    ADD CONSTRAINT pk_gwb_yearly_status PRIMARY KEY (gys_id);


--
-- Name: pk_gwbrcf; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY gwb_reason4chemical_failure
    ADD CONSTRAINT pk_gwbrcf PRIMARY KEY (gys_id, grcf_id);


--
-- Name: pk_gwbrqf; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY gwb_reason4quantity_failure
    ADD CONSTRAINT pk_gwbrqf PRIMARY KEY (gys_id, grqf_id);


--
-- Name: pk_gwcs_id; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY gw_chemical_status
    ADD CONSTRAINT pk_gwcs_id PRIMARY KEY (gys_id, eumg_id, wbpm_id, opt_id);


--
-- Name: pk_gwqs; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY gw_quantity_status
    ADD CONSTRAINT pk_gwqs PRIMARY KEY (gys_id, wbpm_id, eumg_id, opt_id);


--
-- Name: pk_hdh; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY hoedanigheid_type
    ADD CONSTRAINT pk_hdh PRIMARY KEY (hdh_id);


--
-- Name: pk_hdo_identfiers; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY hdo_identfiers
    ADD CONSTRAINT pk_hdo_identfiers PRIMARY KEY (hdo_id, local_id, namespace_id);


--
-- Name: pk_hdo_names; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY hdo_names
    ADD CONSTRAINT pk_hdo_names PRIMARY KEY (hdo_id);


--
-- Name: pk_hydro_object; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY hydro_object
    ADD CONSTRAINT pk_hydro_object PRIMARY KEY (hdo_id);


--
-- Name: pk_iin; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY namespace_type
    ADD CONSTRAINT pk_iin PRIMARY KEY (ns_id);


--
-- Name: pk_info_stream_activity; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY info_stream_activity
    ADD CONSTRAINT pk_info_stream_activity PRIMARY KEY (isac_id);


--
-- Name: pk_information_stream; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY information_stream
    ADD CONSTRAINT pk_information_stream PRIMARY KEY (ims_id);


--
-- Name: pk_islb; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY info_stream_legal_background
    ADD CONSTRAINT pk_islb PRIMARY KEY (ims_id, lgr_id);


--
-- Name: pk_kaarten_sgbp_id_id; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY kaarten_sgbp
    ADD CONSTRAINT pk_kaarten_sgbp_id_id PRIMARY KEY (ksgbp_id);


--
-- Name: pk_kwod; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY kwaliteitsoordeel_type
    ADD CONSTRAINT pk_kwod PRIMARY KEY (kwod_id);


--
-- Name: pk_legislation_level; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY legislation_level_type
    ADD CONSTRAINT pk_legislation_level PRIMARY KEY (lgl_id);


--
-- Name: pk_lom; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY level_of_area_type
    ADD CONSTRAINT pk_lom PRIMARY KEY (loa_id);


--
-- Name: pk_mcpm; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY monitored_compartiment
    ADD CONSTRAINT pk_mcpm PRIMARY KEY (mno_id, cptm_id);


--
-- Name: pk_measure43_function; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY sw_measure43_function
    ADD CONSTRAINT pk_measure43_function PRIMARY KEY (me43_id, smee_id);


--
-- Name: pk_measure_progress_completed; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY measure_progress_completed
    ADD CONSTRAINT pk_measure_progress_completed PRIMARY KEY (measure_progress_completedid);


--
-- Name: pk_measurement_regime_type; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY measurement_regime_type
    ADD CONSTRAINT pk_measurement_regime_type PRIMARY KEY (mmr_id);


--
-- Name: pk_mfp; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY monitoring_feature_positioning_method
    ADD CONSTRAINT pk_mfp PRIMARY KEY (mnf_id, pba_id);


--
-- Name: pk_mfr; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY monitoring_feature_report_to
    ADD CONSTRAINT pk_mfr PRIMARY KEY (mnf_id, lgr_id, report_date);


--
-- Name: pk_mmpa; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY measure_per_man_protected_area
    ADD CONSTRAINT pk_mmpa PRIMARY KEY (mtm_id, wpa_id);


--
-- Name: pk_mmz; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY measure_per_man_reg_or_restr_zone
    ADD CONSTRAINT pk_mmz PRIMARY KEY (mtm_id, mrz_id);


--
-- Name: pk_mnf_parameter; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY mnf_parameter
    ADD CONSTRAINT pk_mnf_parameter PRIMARY KEY (mnf_id, name);


--
-- Name: pk_monitored_measure; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY monitored_measure
    ADD CONSTRAINT pk_monitored_measure PRIMARY KEY (mtm_id);


--
-- Name: pk_monitored_measure_eu_fund; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY monitored_measure_eu_fund
    ADD CONSTRAINT pk_monitored_measure_eu_fund PRIMARY KEY (mtm_id, euf_id);


--
-- Name: pk_monitoring_feature; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY monitoring_feature
    ADD CONSTRAINT pk_monitoring_feature PRIMARY KEY (mnf_id);


--
-- Name: pk_monitoring_object; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY monitoring_object
    ADD CONSTRAINT pk_monitoring_object PRIMARY KEY (mno_id);


--
-- Name: pk_monitoring_object_genealogy; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY monitoring_object_genealogy
    ADD CONSTRAINT pk_monitoring_object_genealogy PRIMARY KEY (mno_id_supersedes, mno_id_superseded_by);


--
-- Name: pk_monitoring_object_hierarchy; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY monitoring_object_hierarchy
    ADD CONSTRAINT pk_monitoring_object_hierarchy PRIMARY KEY (mno_id_narrower, mno_id_broader);


--
-- Name: pk_monitoring_object_other_ids; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY monitoring_object_other_ids
    ADD CONSTRAINT pk_monitoring_object_other_ids PRIMARY KEY (moi_id);


--
-- Name: pk_monitoring_use; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY monitoring_use
    ADD CONSTRAINT pk_monitoring_use PRIMARY KEY (gms_id, mtt_id);


--
-- Name: pk_mrz; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY management_regulation_or_restriction_zone
    ADD CONSTRAINT pk_mrz PRIMARY KEY (mrz_id);


--
-- Name: pk_mrzc; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY management_regulation_or_restriction_zone_collection
    ADD CONSTRAINT pk_mrzc PRIMARY KEY (mzc_id);


--
-- Name: pk_msp; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY measure_progress
    ADD CONSTRAINT pk_msp PRIMARY KEY (mtm_id, mst_id, year);


--
-- Name: pk_mst; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY measure_status_type
    ADD CONSTRAINT pk_mst PRIMARY KEY (mst_id);


--
-- Name: pk_mzc_legal_basis; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY mzc_legal_basis
    ADD CONSTRAINT pk_mzc_legal_basis PRIMARY KEY (mzc_id, lgr_id);


--
-- Name: pk_natural_background_levels; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY natural_background_levels
    ADD CONSTRAINT pk_natural_background_levels PRIMARY KEY (nbl_id);


--
-- Name: pk_nl_measure; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY supp_add_measure_type
    ADD CONSTRAINT pk_nl_measure PRIMARY KEY (smnl_id);


--
-- Name: pk_norm; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY norm
    ADD CONSTRAINT pk_norm PRIMARY KEY (nrm_id);


--
-- Name: pk_norm_feature; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY norm_feature
    ADD CONSTRAINT pk_norm_feature PRIMARY KEY (nrm_id, hdo_id);


--
-- Name: pk_norm_groep_type; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY norm_groep_type
    ADD CONSTRAINT pk_norm_groep_type PRIMARY KEY (nmgp_id);


--
-- Name: pk_norm_hulp_mapping; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY norm_hulp_mapping
    ADD CONSTRAINT pk_norm_hulp_mapping PRIMARY KEY (nhm_id);


--
-- Name: pk_norm_kader_type; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY norm_kader_type
    ADD CONSTRAINT pk_norm_kader_type PRIMARY KEY (nmkd_id);


--
-- Name: pk_normpakket; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY normpakket
    ADD CONSTRAINT pk_normpakket PRIMARY KEY (nmpk_id);


--
-- Name: pk_normwaarde; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY norm_value
    ADD CONSTRAINT pk_normwaarde PRIMARY KEY (nrmv_id);


--
-- Name: pk_nwf; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY network_facility
    ADD CONSTRAINT pk_nwf PRIMARY KEY (emf_id, emn_id, linking_time_begin);


--
-- Name: pk_obex; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY objectives_exemption_type
    ADD CONSTRAINT pk_obex PRIMARY KEY (obex_id);


--
-- Name: pk_object_type; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY object_type
    ADD CONSTRAINT pk_object_type PRIMARY KEY (obj_id);


--
-- Name: pk_obmb; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY other_basic_measure113b_type
    ADD CONSTRAINT pk_obmb PRIMARY KEY (obmb_id);


--
-- Name: pk_obp; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY observation_process
    ADD CONSTRAINT pk_obp PRIMARY KEY (obp_id);


--
-- Name: pk_obp01; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY observation_process_copy_dietmar
    ADD CONSTRAINT pk_obp01 PRIMARY KEY (obp_id);


--
-- Name: pk_observation; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY observation
    ADD CONSTRAINT pk_observation PRIMARY KEY (obs_id);


--
-- Name: pk_observation_context; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY observation_context
    ADD CONSTRAINT pk_observation_context PRIMARY KEY (obs_id_source, obs_id_target);


--
-- Name: pk_observation_parameter; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY observation_parameter
    ADD CONSTRAINT pk_observation_parameter PRIMARY KEY (obs_id, name);


--
-- Name: pk_observed_feature; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY observed_feature
    ADD CONSTRAINT pk_observed_feature PRIMARY KEY (hdo_id, obs_id);


--
-- Name: pk_observed_property_type; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY observed_property_type
    ADD CONSTRAINT pk_observed_property_type PRIMARY KEY (opt_id);


--
-- Name: pk_observing_capability; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY observing_capability
    ADD CONSTRAINT pk_observing_capability PRIMARY KEY (osc_id);


--
-- Name: pk_observing_capability_observation; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY observing_capability_observation
    ADD CONSTRAINT pk_observing_capability_observation PRIMARY KEY (ocbs_id);


--
-- Name: pk_observing_capability_sample; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY observing_capability_sample
    ADD CONSTRAINT pk_observing_capability_sample PRIMARY KEY (ocsa_id);


--
-- Name: pk_ocr; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY object_state_column_required
    ADD CONSTRAINT pk_ocr PRIMARY KEY (ost_id, table_name, column_name);


--
-- Name: pk_ocrp; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY observing_capability_responsible_party
    ADD CONSTRAINT pk_ocrp PRIMARY KEY (ocrp_id);


--
-- Name: pk_ojg; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY object_group
    ADD CONSTRAINT pk_ojg PRIMARY KEY (ojg_id);


--
-- Name: pk_ojge; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY object_group_element
    ADD CONSTRAINT pk_ojge PRIMARY KEY (ojg_id, obj_id);


--
-- Name: pk_operational_activity_period; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY operational_activity_period
    ADD CONSTRAINT pk_operational_activity_period PRIMARY KEY (emf_id, activity_begin);


--
-- Name: pk_opt_class_result_type_type; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY opt_class_result_type_type
    ADD CONSTRAINT pk_opt_class_result_type_type PRIMARY KEY (observed_property_type_class_type, result_type_type);


--
-- Name: pk_organisation_category_type; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY organisation_category_type
    ADD CONSTRAINT pk_organisation_category_type PRIMARY KEY (ocat_id);


--
-- Name: pk_organisatorische_eenheid; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY organisatorische_eenheid
    ADD CONSTRAINT pk_organisatorische_eenheid PRIMARY KEY (ore_id);


--
-- Name: pk_organisatorische_eenheid_wkpusergroup; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY organisatorische_eenheid_wkpusergroup
    ADD CONSTRAINT pk_organisatorische_eenheid_wkpusergroup PRIMARY KEY (organisatorische_eenheid_wkpusergroupid);


--
-- Name: pk_other_monitoring_use_type; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY other_monitoring_use_type
    ADD CONSTRAINT pk_other_monitoring_use_type PRIMARY KEY (omut_id);


--
-- Name: pk_page; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY page
    ADD CONSTRAINT pk_page PRIMARY KEY (page_id);


--
-- Name: pk_page_group; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY page_group
    ADD CONSTRAINT pk_page_group PRIMARY KEY (pg_id);


--
-- Name: pk_page_pagegroup; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY page_pagegroup
    ADD CONSTRAINT pk_page_pagegroup PRIMARY KEY (pagepg_id);


--
-- Name: pk_parameter_aquo_ds_20160105; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY parameter_aquo_ds_20160105
    ADD CONSTRAINT pk_parameter_aquo_ds_20160105 PRIMARY KEY (code);


--
-- Name: pk_parameter_frequency; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY quality_element
    ADD CONSTRAINT pk_parameter_frequency PRIMARY KEY (qem_id);


--
-- Name: pk_parameter_use_type; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY parameter_use_type
    ADD CONSTRAINT pk_parameter_use_type PRIMARY KEY (prus_id);


--
-- Name: pk_pat_id; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY physical_alteration_type
    ADD CONSTRAINT pk_pat_id PRIMARY KEY (pat_id);


--
-- Name: pk_pba; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY plaatsbepalingsapparaat_type
    ADD CONSTRAINT pk_pba PRIMARY KEY (pba_id);


--
-- Name: pk_pmf; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY planned_feature_monitoring
    ADD CONSTRAINT pk_pmf PRIMARY KEY (pmf_id);


--
-- Name: pk_pmfp; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY projection
    ADD CONSTRAINT pk_pmfp PRIMARY KEY (pmfp_id);


--
-- Name: pk_pmo; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY program_monitoring_object
    ADD CONSTRAINT pk_pmo PRIMARY KEY (program_mno_id, object_mno_id);


--
-- Name: pk_pollutant_trend; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY pollutant_trend
    ADD CONSTRAINT pk_pollutant_trend PRIMARY KEY (pltr_id);


--
-- Name: pk_pom_base_measure; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY pom_base_measure113a
    ADD CONSTRAINT pk_pom_base_measure PRIMARY KEY (pbm_id);


--
-- Name: pk_pom_other_basic_measure113b; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY pom_other_basic_measure113b
    ADD CONSTRAINT pk_pom_other_basic_measure113b PRIMARY KEY (pobb_id);


--
-- Name: pk_pressure_category; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY pressure_category_type
    ADD CONSTRAINT pk_pressure_category PRIMARY KEY (pcat_id);


--
-- Name: pk_pressure_measures_checklist; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY sw_pressure_requiring_supp_add_measures
    ADD CONSTRAINT pk_pressure_measures_checklist PRIMARY KEY (sprm_id);


--
-- Name: pk_process_type; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY process_type
    ADD CONSTRAINT pk_process_type PRIMARY KEY (prc_id);


--
-- Name: pk_protected_area_type; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY protected_area_type
    ADD CONSTRAINT pk_protected_area_type PRIMARY KEY (pat_id);


--
-- Name: pk_prr; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY pressure_relevance_type
    ADD CONSTRAINT pk_prr PRIMARY KEY (prr_id);


--
-- Name: pk_qe_ecological_type; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY qe_ecological_type
    ADD CONSTRAINT pk_qe_ecological_type PRIMARY KEY (qeel_id);


--
-- Name: pk_quality_element_observation; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY quality_element_observation
    ADD CONSTRAINT pk_quality_element_observation PRIMARY KEY (qeo_id);


--
-- Name: pk_quality_element_sample; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY quality_element_sample
    ADD CONSTRAINT pk_quality_element_sample PRIMARY KEY (qes_id);


--
-- Name: pk_rbmp; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY river_basin_management_plan
    ADD CONSTRAINT pk_rbmp PRIMARY KEY (rbmp_id);


--
-- Name: pk_rct_id; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY reason_change_type
    ADD CONSTRAINT pk_rct_id PRIMARY KEY (rct_id);


--
-- Name: pk_rel_samp_feat_role_type; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY rel_samp_feat_role_type
    ADD CONSTRAINT pk_rel_samp_feat_role_type PRIMARY KEY (rsfr_id);


--
-- Name: pk_related_hydro_object; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY related_hydro_object
    ADD CONSTRAINT pk_related_hydro_object PRIMARY KEY (from_hdo, to_hdo, rrt_id);


--
-- Name: pk_relation_gwb_swb; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY relation_gwb_swb
    ADD CONSTRAINT pk_relation_gwb_swb PRIMARY KEY (gwb_id, swb_id, gwsw_id);


--
-- Name: pk_relation_ore_wbd; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY relation_ore_wbd
    ADD CONSTRAINT pk_relation_ore_wbd PRIMARY KEY (ore_wbd_id);


--
-- Name: pk_relation_type; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY relation_type
    ADD CONSTRAINT pk_relation_type PRIMARY KEY (rlt_id);


--
-- Name: pk_report_version; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY report_version
    ADD CONSTRAINT pk_report_version PRIMARY KEY (rpv_id);


--
-- Name: pk_result_acquisition_source_type; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY result_acquisition_source_type
    ADD CONSTRAINT pk_result_acquisition_source_type PRIMARY KEY (ras_id);


--
-- Name: pk_rewab_type; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY rewab_type
    ADD CONSTRAINT pk_rewab_type PRIMARY KEY (rwb_id);


--
-- Name: pk_rhr; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY rel_hdo_role_type
    ADD CONSTRAINT pk_rhr PRIMARY KEY (rhr_id);


--
-- Name: pk_river_basin_disrict; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY river_basin_disrict
    ADD CONSTRAINT pk_river_basin_disrict PRIMARY KEY (rbd_id);


--
-- Name: pk_role_type; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY obs_ctx_role_type
    ADD CONSTRAINT pk_role_type PRIMARY KEY (ocr_id);


--
-- Name: pk_rpp; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY reporting_period
    ADD CONSTRAINT pk_rpp PRIMARY KEY (rpp_id);


--
-- Name: pk_rrt; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY rel_role_type
    ADD CONSTRAINT pk_rrt PRIMARY KEY (rrt_id);


--
-- Name: pk_rrt_from_to; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY related_monitoring_object
    ADD CONSTRAINT pk_rrt_from_to PRIMARY KEY (from_mno, to_mno, rrt_id);


--
-- Name: pk_rsf; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY related_sampling_feature
    ADD CONSTRAINT pk_rsf PRIMARY KEY (mnf_id_source, mnf_id_target);


--
-- Name: pk_sampled_feature; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY sampled_feature
    ADD CONSTRAINT pk_sampled_feature PRIMARY KEY (hdo_id, mnf_id);


--
-- Name: pk_sampling_proces; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY sampling_proces
    ADD CONSTRAINT pk_sampling_proces PRIMARY KEY (smp_id);


--
-- Name: pk_sc_id; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY system_configuration
    ADD CONSTRAINT pk_sc_id PRIMARY KEY (sc_id);


--
-- Name: pk_scss; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY sw_chemical_substance_status
    ADD CONSTRAINT pk_scss PRIMARY KEY (sys_id, opt_id, eumg_id, wbpm_id);


--
-- Name: pk_ses; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY sw_ecological_status
    ADD CONSTRAINT pk_ses PRIMARY KEY (sys_id, opt_id, eumg_id, wbpm_id);


--
-- Name: pk_smeu; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY sw_supp_measure_eu_type
    ADD CONSTRAINT pk_smeu PRIMARY KEY (smeu_id);


--
-- Name: pk_specialised_emf_type; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY specialised_emf_type
    ADD CONSTRAINT pk_specialised_emf_type PRIMARY KEY (semf_id);


--
-- Name: pk_ssg; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY substance_group
    ADD CONSTRAINT pk_ssg PRIMARY KEY (ssg_id);


--
-- Name: pk_ssge; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY substance_group_element
    ADD CONSTRAINT pk_ssge PRIMARY KEY (ssge_id, chs_id);


--
-- Name: pk_station_level_type; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY station_level_type
    ADD CONSTRAINT pk_station_level_type PRIMARY KEY (slt_id);


--
-- Name: pk_station_type_type; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY station_type_type
    ADD CONSTRAINT pk_station_type_type PRIMARY KEY (stt_id);


--
-- Name: pk_stcc_eumg_sys; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY sw_testing_conclusion
    ADD CONSTRAINT pk_stcc_eumg_sys PRIMARY KEY (stcc_id, sys_id, eumg_id);


--
-- Name: pk_subsite_type; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY subsite_type
    ADD CONSTRAINT pk_subsite_type PRIMARY KEY (sst_id);


--
-- Name: pk_substrate_type; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY substrate_type
    ADD CONSTRAINT pk_substrate_type PRIMARY KEY (sub_id);


--
-- Name: pk_sw_pressure_type; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY sw_pressure_type
    ADD CONSTRAINT pk_sw_pressure_type PRIMARY KEY (sprs_id);


--
-- Name: pk_sw_pressure_type_driver_ids; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY sw_pressure_type_driver
    ADD CONSTRAINT pk_sw_pressure_type_driver_ids PRIMARY KEY (sprs_id, driver_id);


--
-- Name: pk_sw_pressure_type_type_category; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY sw_pressure_type_type_category
    ADD CONSTRAINT pk_sw_pressure_type_type_category PRIMARY KEY (sprs_id, swc_id);


--
-- Name: pk_sw_pressures_preventing_good_status; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY sw_pressures_preventing_good_status
    ADD CONSTRAINT pk_sw_pressures_preventing_good_status PRIMARY KEY (spg_id);


--
-- Name: pk_sw_required_supp_measure; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY sw_required_supp_measure
    ADD CONSTRAINT pk_sw_required_supp_measure PRIMARY KEY (sprm_id, smnl_id);


--
-- Name: pk_sw_test_value; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY sw_test_value
    ADD CONSTRAINT pk_sw_test_value PRIMARY KEY (stcc_id, nrmv_id);


--
-- Name: pk_sw_typology_type; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY sw_typology_type
    ADD CONSTRAINT pk_sw_typology_type PRIMARY KEY (styp_id);


--
-- Name: pk_swap; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY sw_abstraction_point
    ADD CONSTRAINT pk_swap PRIMARY KEY (sasp_id);


--
-- Name: pk_swat; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY sw_abstraction_type
    ADD CONSTRAINT pk_swat PRIMARY KEY (swat_id);


--
-- Name: pk_swb_art43b_excemption; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY swb_art43b_excemption
    ADD CONSTRAINT pk_swb_art43b_excemption PRIMARY KEY (swb_id, a43b_id);


--
-- Name: pk_swb_chem_exemp_pollutant; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY swb_chem_exemp_pollutant
    ADD CONSTRAINT pk_swb_chem_exemp_pollutant PRIMARY KEY (swce_id, chs_id);


--
-- Name: pk_swb_chemical_exemption; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY swb_exemption
    ADD CONSTRAINT pk_swb_chemical_exemption PRIMARY KEY (swce_id);


--
-- Name: pk_swb_ecol_exemp_qe; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY swb_ecol_exemp_qe
    ADD CONSTRAINT pk_swb_ecol_exemp_qe PRIMARY KEY (swce_id, opt_id);


--
-- Name: pk_swb_measure_43a; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY swb_measures_43a
    ADD CONSTRAINT pk_swb_measure_43a PRIMARY KEY (swb_id, fu43_id);


--
-- Name: pk_swb_physical_alteration_ids; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY swb_physical_alteration
    ADD CONSTRAINT pk_swb_physical_alteration_ids PRIMARY KEY (swb_id, pat_id);


--
-- Name: pk_swb_pressure; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY swb_pressure
    ADD CONSTRAINT pk_swb_pressure PRIMARY KEY (swbp_id);


--
-- Name: pk_swb_pressure_impact_ids; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY swb_pressure_impact
    ADD CONSTRAINT pk_swb_pressure_impact_ids PRIMARY KEY (swbp_id, impact_id);


--
-- Name: pk_swb_status; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY gw_swb_status
    ADD CONSTRAINT pk_swb_status PRIMARY KEY (swb_id, gwsy, opt_id);


--
-- Name: pk_swb_yearly_status; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY swb_yearly_status
    ADD CONSTRAINT pk_swb_yearly_status PRIMARY KEY (sys_id);


--
-- Name: pk_swc; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY sw_category_type
    ADD CONSTRAINT pk_swc PRIMARY KEY (swc_id);


--
-- Name: pk_swp; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY sw_aggregated_pressure_type
    ADD CONSTRAINT pk_swp PRIMARY KEY (swap_id);


--
-- Name: pk_swpr_id; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY wb_prognosis
    ADD CONSTRAINT pk_swpr_id PRIMARY KEY (wbpr_id);


--
-- Name: pk_taxon_type; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY taxon_type
    ADD CONSTRAINT pk_taxon_type PRIMARY KEY (txn_id);


--
-- Name: pk_tge; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY taxa_group_element
    ADD CONSTRAINT pk_tge PRIMARY KEY (txg_id, txn_id);


--
-- Name: pk_thema_actie_organisatorische_eenheid_voortgang; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY thema_actie_organisatorische_eenheid_voortgang
    ADD CONSTRAINT pk_thema_actie_organisatorische_eenheid_voortgang PRIMARY KEY (taov_id);


--
-- Name: pk_thema_acties; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY thema_acties
    ADD CONSTRAINT pk_thema_acties PRIMARY KEY (ta_id);


--
-- Name: pk_thema_overzicht_groep_organisatorische_eenheden; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY thema_overzicht_groep_organisatorische_eenheden
    ADD CONSTRAINT pk_thema_overzicht_groep_organisatorische_eenheden PRIMARY KEY (tog_id, ore_id);


--
-- Name: pk_thema_overzicht_groep_river_basin_disrict; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY thema_overzicht_groep_river_basin_disrict
    ADD CONSTRAINT pk_thema_overzicht_groep_river_basin_disrict PRIMARY KEY (tog_id, rbd_id);


--
-- Name: pk_thema_overzicht_groep_wkpusers; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY thema_overzicht_groep_wkpusers
    ADD CONSTRAINT pk_thema_overzicht_groep_wkpusers PRIMARY KEY (tog_id, wkpuserid);


--
-- Name: pk_thema_overzicht_groepen; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY thema_overzicht_groepen
    ADD CONSTRAINT pk_thema_overzicht_groepen PRIMARY KEY (tog_id);


--
-- Name: pk_thema_overzicht_statussen; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY thema_overzicht_statussen
    ADD CONSTRAINT pk_thema_overzicht_statussen PRIMARY KEY (tos_id);


--
-- Name: pk_themas; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY themas
    ADD CONSTRAINT pk_themas PRIMARY KEY (t_id);


--
-- Name: pk_txg; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY taxa_group
    ADD CONSTRAINT pk_txg PRIMARY KEY (txg_id);


--
-- Name: pk_type_environmental_domain; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY environmental_domain_code
    ADD CONSTRAINT pk_type_environmental_domain PRIMARY KEY (emd_id);


--
-- Name: pk_type_object_state; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY object_state_type
    ADD CONSTRAINT pk_type_object_state PRIMARY KEY (ost_id);


--
-- Name: pk_typering_type; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY typering_type
    ADD CONSTRAINT pk_typering_type PRIMARY KEY (typ_id);


--
-- Name: pk_valid_column_uom; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY valid_column_uom
    ADD CONSTRAINT pk_valid_column_uom PRIMARY KEY (vcu_id);


--
-- Name: pk_volumestroom_type; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY volumestroom_type
    ADD CONSTRAINT pk_volumestroom_type PRIMARY KEY (vst_id);


--
-- Name: pk_volumestroom_type_bronnen; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY volumestroom_type_bronnen
    ADD CONSTRAINT pk_volumestroom_type_bronnen PRIMARY KEY (vtb_id);


--
-- Name: pk_waarde_bepalings_methode; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY waarde_bepalings_methode_type
    ADD CONSTRAINT pk_waarde_bepalings_methode PRIMARY KEY (wbpm_id);


--
-- Name: pk_watercourse; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY watercourse
    ADD CONSTRAINT pk_watercourse PRIMARY KEY (wtc_id);


--
-- Name: pk_wbd_pwa_overlap; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY waterbody_protected_area_intersection
    ADD CONSTRAINT pk_wbd_pwa_overlap PRIMARY KEY (wbpa_id);


--
-- Name: pk_wbm; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY waarde_bewerkings_methode_type
    ADD CONSTRAINT pk_wbm PRIMARY KEY (wbm_id);


--
-- Name: pk_wbsc; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY wb_status_change_motivation
    ADD CONSTRAINT pk_wbsc PRIMARY KEY (wbsc_id);


--
-- Name: pk_wfd_groundwaterbody; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY ground_water_body
    ADD CONSTRAINT pk_wfd_groundwaterbody PRIMARY KEY (gwb_id);


--
-- Name: pk_wfd_monitoring_station; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY monitoring_station
    ADD CONSTRAINT pk_wfd_monitoring_station PRIMARY KEY (mts_id);


--
-- Name: pk_wfd_protected_area; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY wfd_protected_area
    ADD CONSTRAINT pk_wfd_protected_area PRIMARY KEY (wpa_id);


--
-- Name: pk_wfd_qe_gw; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY wfd_qe_gwtype
    ADD CONSTRAINT pk_wfd_qe_gw PRIMARY KEY (opt_id);


--
-- Name: pk_wfd_qe_swtype; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY wfd_qe_swtype
    ADD CONSTRAINT pk_wfd_qe_swtype PRIMARY KEY (opt_id, swt_id);


--
-- Name: pk_wfd_status_code; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY wfd_status_code
    ADD CONSTRAINT pk_wfd_status_code PRIMARY KEY (wsc_id);


--
-- Name: pk_wfd_surface_water_body; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY surface_water_body
    ADD CONSTRAINT pk_wfd_surface_water_body PRIMARY KEY (swb_id);


--
-- Name: pk_wfd_water_body; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY water_body
    ADD CONSTRAINT pk_wfd_water_body PRIMARY KEY (wbd_id);


--
-- Name: pk_wkpuser_pagegroup; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY wkpuser_pagegroup
    ADD CONSTRAINT pk_wkpuser_pagegroup PRIMARY KEY (wupg_id);


--
-- Name: pk_wkpusergroupid; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY wkpusergroup
    ADD CONSTRAINT pk_wkpusergroupid PRIMARY KEY (wkpusergroupid);


--
-- Name: pk_wkpuserid; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY wkpuser_settings
    ADD CONSTRAINT pk_wkpuserid PRIMARY KEY (wkpuserid);


--
-- Name: pk_wkr_version; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY wkr_version
    ADD CONSTRAINT pk_wkr_version PRIMARY KEY (wkrv_id);


--
-- Name: pk_wtclt; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY watercourse_local_type
    ADD CONSTRAINT pk_wtclt PRIMARY KEY (wtc_id, value, locale);


--
-- Name: pk_yes_no_not_applicable_type; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY yes_no_not_applicable_type
    ADD CONSTRAINT pk_yes_no_not_applicable_type PRIMARY KEY (ynna_id);


--
-- Name: pk_zone_type_code; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY zone_type_code
    ADD CONSTRAINT pk_zone_type_code PRIMARY KEY (ztc_id);


--
-- Name: pl_me43_id; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY sw_measure43_nl_type
    ADD CONSTRAINT pl_me43_id PRIMARY KEY (me43_id);


--
-- Name: pl_mft; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY measure_finance
    ADD CONSTRAINT pl_mft PRIMARY KEY (mtm_id, mft_id);


--
-- Name: pl_mft_id; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY measure_finance_type
    ADD CONSTRAINT pl_mft_id PRIMARY KEY (mtf_id);


--
-- Name: profile_wkpuser_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY profile
    ADD CONSTRAINT profile_wkpuser_pkey PRIMARY KEY (wkpuserid);


--
-- Name: role_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY role
    ADD CONSTRAINT role_pkey PRIMARY KEY (roleid);


--
-- Name: role_rolename_key; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY role
    ADD CONSTRAINT role_rolename_key UNIQUE (rolename);


--
-- Name: sample_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY sample
    ADD CONSTRAINT sample_pkey PRIMARY KEY (smpl_id);


--
-- Name: transformation_name_key; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY transformation
    ADD CONSTRAINT transformation_name_key UNIQUE (name);


--
-- Name: transformation_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY transformation
    ADD CONSTRAINT transformation_pkey PRIMARY KEY (transformationid);


--
-- Name: uk_bio_observation; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY bio_observation
    ADD CONSTRAINT uk_bio_observation UNIQUE (obs_id, levensstadium_id, lengte_klasse_id, geslacht_id, verschijningsvorm_id, levensvorm_id, gedrag_id);


--
-- Name: uk_hydro_objects; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY hydro_object
    ADD CONSTRAINT uk_hydro_objects UNIQUE (inspire_id_local_id, inspire_id_namespace, wkrv_id, hydro_object_type);


--
-- Name: uk_measure_ids; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY supp_add_measure_type
    ADD CONSTRAINT uk_measure_ids UNIQUE (rbmp_id, namespace_id, local_id);


--
-- Name: uk_observed_property_type_six_columns; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY observed_property_type
    ADD CONSTRAINT uk_observed_property_type_six_columns UNIQUE (hoedanigheid_id, object_group_id, quantity_id, taxa_group_id, substance_group_id, indicator_id);


--
-- Name: uk_omschrijving; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY pressure_relevance_type
    ADD CONSTRAINT uk_omschrijving UNIQUE (omschrijving);


--
-- Name: uk_prognosis; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY wb_prognosis
    ADD CONSTRAINT uk_prognosis UNIQUE (year, opt_id, swb_id);


--
-- Name: uk_qegw_id; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY wfd_qe_gwtype
    ADD CONSTRAINT uk_qegw_id UNIQUE (qegw_id);


--
-- Name: uk_swee_measure; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY swb_measures_43a
    ADD CONSTRAINT uk_swee_measure UNIQUE (swee_id);


--
-- Name: uq_code; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY waarde_bepalings_methode_type
    ADD CONSTRAINT uq_code UNIQUE (code);


--
-- Name: uq_hdo_names; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY hdo_names
    ADD CONSTRAINT uq_hdo_names UNIQUE (hdo_id, name, language);


--
-- Name: uq_norm_hulp_mapping_ln; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY norm_hulp_mapping
    ADD CONSTRAINT uq_norm_hulp_mapping_ln UNIQUE (lokale_naam);


--
-- Name: uq_norm_hulp_mapping_ptc; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY norm_hulp_mapping
    ADD CONSTRAINT uq_norm_hulp_mapping_ptc UNIQUE (parameter_typering_code);


--
-- Name: validation_importtype_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY validation_importtype
    ADD CONSTRAINT validation_importtype_pkey PRIMARY KEY (validationid, importtypeid);


--
-- Name: validation_name_key; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY validation
    ADD CONSTRAINT validation_name_key UNIQUE (name);


--
-- Name: validation_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY validation
    ADD CONSTRAINT validation_pkey PRIMARY KEY (validationid);


--
-- Name: wkpuser_importtype_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY wkpuser_importtype
    ADD CONSTRAINT wkpuser_importtype_pkey PRIMARY KEY (wkpuserid, importtypeid);


--
-- Name: wkpuser_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY wkpuser
    ADD CONSTRAINT wkpuser_pkey PRIMARY KEY (wkpuserid);


--
-- Name: wkpuser_role_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY wkpuserinrole
    ADD CONSTRAINT wkpuser_role_pkey PRIMARY KEY (wkpuserid, roleid);


--
-- Name: wkpuser_username_key; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY wkpuser
    ADD CONSTRAINT wkpuser_username_key UNIQUE (username);


--
-- Name: wkpuser_wkpusergroup_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY wkpuser_wkpusergroup
    ADD CONSTRAINT wkpuser_wkpusergroup_pkey PRIMARY KEY (wkpuserid, wkpusergroupid);



--
-- Name: pk_id; Type: CONSTRAINT; Schema: wfd_reporting; Owner: -
--

ALTER TABLE ONLY geological_formation_enum
    ADD CONSTRAINT pk_id PRIMARY KEY (nl_id);



--
-- Name: FKI_VerwerkingsVerslagRegel_VerwerkingsVerslag; Type: INDEX; Schema: public; Owner: -
--

CREATE INDEX "FKI_VerwerkingsVerslagRegel_VerwerkingsVerslag" ON "VerwerkingsVerslagRegel" USING btree ("verwerkingsVerslagId");


--
-- Name: FKI_VerwerkingsVerslagRegel_VerwerkingsVerslagRegeloort; Type: INDEX; Schema: public; Owner: -
--

CREATE INDEX "FKI_VerwerkingsVerslagRegel_VerwerkingsVerslagRegeloort" ON "VerwerkingsVerslagRegel" USING btree ("verwerkingsVerslagRegelSoortId");


--
-- Name: FKI_VerwerkingsVerslag_VerwerkingsVerslagStatus; Type: INDEX; Schema: public; Owner: -
--

CREATE INDEX "FKI_VerwerkingsVerslag_VerwerkingsVerslagStatus" ON "VerwerkingsVerslag" USING btree ("actieId");


--
-- Name: eumg_id_idx; Type: INDEX; Schema: public; Owner: -
--

CREATE INDEX eumg_id_idx ON sw_chemical_substance_status USING btree (eumg_id DESC NULLS LAST);


--
-- Name: idx_hdo_wkrv; Type: INDEX; Schema: public; Owner: -
--

CREATE INDEX idx_hdo_wkrv ON hydro_object USING btree (hdo_id, wkrv_id DESC NULLS LAST);


--
-- Name: idx_hydro_object_inspire_id_local_id; Type: INDEX; Schema: public; Owner: -
--

CREATE INDEX idx_hydro_object_inspire_id_local_id ON hydro_object USING btree (inspire_id_local_id);


--
-- Name: idx_hydro_object_related_hdo_id; Type: INDEX; Schema: public; Owner: -
--

CREATE INDEX idx_hydro_object_related_hdo_id ON hydro_object USING btree (related_hdo_id);


--
-- Name: idx_measure_per_man_reg_or_restr_zone_mrz_id; Type: INDEX; Schema: public; Owner: -
--

CREATE INDEX idx_measure_per_man_reg_or_restr_zone_mrz_id ON measure_per_man_reg_or_restr_zone USING btree (mrz_id);


--
-- Name: idx_measure_per_man_reg_or_restr_zone_mtm_id; Type: INDEX; Schema: public; Owner: -
--

CREATE INDEX idx_measure_per_man_reg_or_restr_zone_mtm_id ON measure_per_man_reg_or_restr_zone USING btree (mtm_id);


--
-- Name: idx_mvoc_swb_id; Type: INDEX; Schema: public; Owner: -
--

CREATE INDEX idx_mvoc_swb_id ON mv_oordeel_chemie_owm USING btree (swb_id);


--
-- Name: idx_mvoe_swb_id; Type: INDEX; Schema: public; Owner: -
--

CREATE INDEX idx_mvoe_swb_id ON mv_oordeel_ecologie_owm USING btree (swb_id);


--
-- Name: idx_network_facility_emf_id; Type: INDEX; Schema: public; Owner: -
--

CREATE INDEX idx_network_facility_emf_id ON network_facility USING btree (emf_id);


--
-- Name: idx_network_facility_emn_id; Type: INDEX; Schema: public; Owner: -
--

CREATE INDEX idx_network_facility_emn_id ON network_facility USING btree (emn_id);


--
-- Name: idx_observation_obs_id; Type: INDEX; Schema: public; Owner: -
--

CREATE INDEX idx_observation_obs_id ON observation USING btree (obs_id);


--
-- Name: idx_observation_observed_property_type; Type: INDEX; Schema: public; Owner: -
--

CREATE INDEX idx_observation_observed_property_type ON observation USING btree (observed_property_type);


--
-- Name: idx_observed_property_type_opt_id; Type: INDEX; Schema: public; Owner: -
--

CREATE INDEX idx_observed_property_type_opt_id ON observed_property_type USING btree (opt_id);


--
-- Name: idx_observing_capability_observation_obs_id; Type: INDEX; Schema: public; Owner: -
--

CREATE INDEX idx_observing_capability_observation_obs_id ON observing_capability_observation USING btree (obs_id);


--
-- Name: INDEX idx_observing_capability_observation_obs_id; Type: COMMENT; Schema: public; Owner: -
--

COMMENT ON INDEX idx_observing_capability_observation_obs_id IS 'Added by SF 2016-04-23';


--
-- Name: idx_supp_add_measure_type_local_id; Type: INDEX; Schema: public; Owner: -
--

CREATE INDEX idx_supp_add_measure_type_local_id ON supp_add_measure_type USING btree (local_id);


--
-- Name: idx_surface_water_body_sw_typology_id; Type: INDEX; Schema: public; Owner: -
--

CREATE INDEX idx_surface_water_body_sw_typology_id ON surface_water_body USING btree (sw_typology_id);


--
-- Name: idx_sw_testing_conclusion_stcc_id; Type: INDEX; Schema: public; Owner: -
--

CREATE INDEX idx_sw_testing_conclusion_stcc_id ON sw_testing_conclusion USING btree (stcc_id);


--
-- Name: INDEX idx_sw_testing_conclusion_stcc_id; Type: COMMENT; Schema: public; Owner: -
--

COMMENT ON INDEX idx_sw_testing_conclusion_stcc_id IS 'Added by SF on 2016-04-13';


--
-- Name: idx_water_body_rbd_id; Type: INDEX; Schema: public; Owner: -
--

CREATE INDEX idx_water_body_rbd_id ON water_body USING btree (rbd_id);


--
-- Name: idx_wfd_protected_area_protected_area_type_id; Type: INDEX; Schema: public; Owner: -
--

CREATE INDEX idx_wfd_protected_area_protected_area_type_id ON wfd_protected_area USING btree (protected_area_type_id);


--
-- Name: ix_applicationid_membership; Type: INDEX; Schema: public; Owner: -
--

CREATE INDEX ix_applicationid_membership ON membership USING btree (applicationid);


--
-- Name: ix_applicationid_role; Type: INDEX; Schema: public; Owner: -
--

CREATE INDEX ix_applicationid_role ON role USING btree (applicationid);


--
-- Name: ix_applicationid_wkpuser; Type: INDEX; Schema: public; Owner: -
--

CREATE INDEX ix_applicationid_wkpuser ON wkpuser USING btree (applicationid);


--
-- Name: ix_importtypeid_validation_importtype; Type: INDEX; Schema: public; Owner: -
--

CREATE INDEX ix_importtypeid_validation_importtype ON validation_importtype USING btree (importtypeid);


--
-- Name: ix_importtypeid_wkpuser_importtype; Type: INDEX; Schema: public; Owner: -
--

CREATE INDEX ix_importtypeid_wkpuser_importtype ON wkpuser_importtype USING btree (importtypeid);


--
-- Name: ix_profile_wkpuser; Type: INDEX; Schema: public; Owner: -
--

CREATE INDEX ix_profile_wkpuser ON wkpuser USING btree (wkpuserid);


--
-- Name: ix_roleid_wkpuserinrole; Type: INDEX; Schema: public; Owner: -
--

CREATE INDEX ix_roleid_wkpuserinrole ON wkpuserinrole USING btree (roleid);


--
-- Name: ix_validationid_validation_importtype; Type: INDEX; Schema: public; Owner: -
--

CREATE INDEX ix_validationid_validation_importtype ON validation_importtype USING btree (validationid);


--
-- Name: ix_wkpuserid_membership; Type: INDEX; Schema: public; Owner: -
--

CREATE INDEX ix_wkpuserid_membership ON membership USING btree (wkpuserid);


--
-- Name: ix_wkpuserid_wkpuser_importtype; Type: INDEX; Schema: public; Owner: -
--

CREATE INDEX ix_wkpuserid_wkpuser_importtype ON wkpuser_importtype USING btree (wkpuserid);


--
-- Name: ix_wkpuserid_wkpuserinrole; Type: INDEX; Schema: public; Owner: -
--

CREATE INDEX ix_wkpuserid_wkpuserinrole ON wkpuserinrole USING btree (wkpuserid);


--
-- Name: ix_wkpusername_wkpuser; Type: INDEX; Schema: public; Owner: -
--

CREATE UNIQUE INDEX ix_wkpusername_wkpuser ON wkpuser USING btree (username);


--
-- Name: observation_idx_result_nature_id01; Type: INDEX; Schema: public; Owner: -
--

CREATE INDEX observation_idx_result_nature_id01 ON observation USING btree (result_nature_id);


--
-- Name: observation_mno_id; Type: INDEX; Schema: public; Owner: -
--

CREATE INDEX observation_mno_id ON observation USING btree (mno_id);


--
-- Name: observation_obs_parm_parent_id; Type: INDEX; Schema: public; Owner: -
--

CREATE INDEX observation_obs_parm_parent_id ON observation USING btree (obs_parm_parent_id);


--
-- Name: observed_feature_obs_id; Type: INDEX; Schema: public; Owner: -
--

CREATE INDEX observed_feature_obs_id ON observed_feature USING btree (obs_id);


--
-- Name: opt_id_idx; Type: INDEX; Schema: public; Owner: -
--

CREATE INDEX opt_id_idx ON sw_chemical_substance_status USING btree (opt_id);


--
-- Name: quality_element_observation_obs_id; Type: INDEX; Schema: public; Owner: -
--

CREATE INDEX quality_element_observation_obs_id ON quality_element_observation USING btree (obs_id);


--
-- Name: INDEX quality_element_observation_obs_id; Type: COMMENT; Schema: public; Owner: -
--

COMMENT ON INDEX quality_element_observation_obs_id IS 'Added by SF on 2016-07-28';


--
-- Name: sidx_abstraction_point_geometry; Type: INDEX; Schema: public; Owner: -
--

CREATE INDEX sidx_abstraction_point_geometry ON abstraction_point USING gist (geometry);


--
-- Name: sidx_environmental_monitoring_facility_representative_point; Type: INDEX; Schema: public; Owner: -
--

CREATE INDEX sidx_environmental_monitoring_facility_representative_point ON environmental_monitoring_facility USING gist (representative_point);


--
-- Name: sidx_ground_water_body_centroid; Type: INDEX; Schema: public; Owner: -
--

CREATE INDEX sidx_ground_water_body_centroid ON ground_water_body USING gist (centroid);


--
-- Name: sidx_management_regulation_or_restriction_zone_geometry; Type: INDEX; Schema: public; Owner: -
--

CREATE INDEX sidx_management_regulation_or_restriction_zone_geometry ON management_regulation_or_restriction_zone USING gist (geometry);

ALTER TABLE management_regulation_or_restriction_zone CLUSTER ON sidx_management_regulation_or_restriction_zone_geometry;


--
-- Name: sidx_management_regulation_or_restriction_zone_geometry_etrs89; Type: INDEX; Schema: public; Owner: -
--

CREATE INDEX sidx_management_regulation_or_restriction_zone_geometry_etrs89 ON management_regulation_or_restriction_zone USING gist (geometry_etrs89);


--
-- Name: sidx_monitoring_object_geometry; Type: INDEX; Schema: public; Owner: -
--

CREATE INDEX sidx_monitoring_object_geometry ON monitoring_object USING gist (geometry);


--
-- Name: sidx_monitoring_object_geometry_etrs89; Type: INDEX; Schema: public; Owner: -
--

CREATE INDEX sidx_monitoring_object_geometry_etrs89 ON monitoring_object USING gist (geometry_etrs89);


--
-- Name: sidx_surface_water_body_representative_point; Type: INDEX; Schema: public; Owner: -
--

CREATE INDEX sidx_surface_water_body_representative_point ON surface_water_body USING gist (representative_point);


--
-- Name: sidx_waterbody_protected_area_intersection_geometry; Type: INDEX; Schema: public; Owner: -
--

CREATE INDEX sidx_waterbody_protected_area_intersection_geometry ON waterbody_protected_area_intersection USING gist (geometry);


--
-- Name: sidx_watercourse_geometryLine; Type: INDEX; Schema: public; Owner: -
--

CREATE INDEX "sidx_watercourse_geometryLine" ON watercourse USING gist ("geometryLine");


--
-- Name: sidx_watercourse_geometrySurface; Type: INDEX; Schema: public; Owner: -
--

CREATE INDEX "sidx_watercourse_geometrySurface" ON watercourse USING gist ("geometrySurface");


--
-- Name: sidx_wfd_protected_area_geometry; Type: INDEX; Schema: public; Owner: -
--

CREATE INDEX sidx_wfd_protected_area_geometry ON wfd_protected_area USING gist (geometry);


--
-- Name: swb_idx; Type: INDEX; Schema: public; Owner: -
--

CREATE INDEX swb_idx ON swb_yearly_status USING btree (swb_id);


--
-- Name: sys_id_idx; Type: INDEX; Schema: public; Owner: -
--

CREATE INDEX sys_id_idx ON sw_chemical_substance_status USING btree (sys_id);


--
-- Name: wbpm_id_idx; Type: INDEX; Schema: public; Owner: -
--

CREATE INDEX wbpm_id_idx ON sw_chemical_substance_status USING btree (wbpm_id DESC NULLS LAST);


--
-- Name: yos_idx; Type: INDEX; Schema: public; Owner: -
--

CREATE INDEX yos_idx ON swb_yearly_status USING btree (year_of_status DESC NULLS LAST);



--
-- Name: fk_idd_idd; Type: FK CONSTRAINT; Schema: domains; Owner: -
--

ALTER TABLE ONLY indicator_descriptor
    ADD CONSTRAINT fk_idd_idd FOREIGN KEY (part_of_idd_id) REFERENCES indicator_descriptor(idd_id);


--
-- Name: fk_idd_opt; Type: FK CONSTRAINT; Schema: domains; Owner: -
--

ALTER TABLE ONLY indicator_descriptor
    ADD CONSTRAINT fk_idd_opt FOREIGN KEY (opt_id) REFERENCES public.observed_property_type(opt_id);



--
-- Name: uitvoering_tpe_id_fk; Type: FK CONSTRAINT; Schema: factsheets; Owner: -
--

ALTER TABLE ONLY rapport_tekst
    ADD CONSTRAINT uitvoering_tpe_id_fk FOREIGN KEY (uitvoering_tpe_id) REFERENCES uitvoering_type(uitvoering_type_id);


--
-- Name: veld_id_fk; Type: FK CONSTRAINT; Schema: factsheets; Owner: -
--

ALTER TABLE ONLY rapport_tekst
    ADD CONSTRAINT veld_id_fk FOREIGN KEY (veld_id) REFERENCES veld(veld_id);


--
-- Name: wb_type_id_fk; Type: FK CONSTRAINT; Schema: factsheets; Owner: -
--

ALTER TABLE ONLY rapport_tekst
    ADD CONSTRAINT wb_type_id_fk FOREIGN KEY (wb_type_id) REFERENCES wb_type(wb_type_id);



--
-- Name: fk_pot_bpg; Type: FK CONSTRAINT; Schema: monprog; Owner: -
--

ALTER TABLE ONLY planned_observation_time
    ADD CONSTRAINT fk_pot_bpg FOREIGN KEY (samples_bepalingsgrens_id) REFERENCES public.bepaling_grens_type(bpg_id);


--
-- Name: fk_pot_qem; Type: FK CONSTRAINT; Schema: monprog; Owner: -
--

ALTER TABLE ONLY planned_observation_time
    ADD CONSTRAINT fk_pot_qem FOREIGN KEY (qem_id) REFERENCES public.quality_element(qem_id);


--
-- Name: fk_qeid_idd; Type: FK CONSTRAINT; Schema: monprog; Owner: -
--

ALTER TABLE ONLY quality_element_indicator_descriptor
    ADD CONSTRAINT fk_qeid_idd FOREIGN KEY (idd_id) REFERENCES domains.indicator_descriptor(idd_id);


--
-- Name: CONSTRAINT fk_qeid_idd ON quality_element_indicator_descriptor; Type: COMMENT; Schema: monprog; Owner: -
--

COMMENT ON CONSTRAINT fk_qeid_idd ON quality_element_indicator_descriptor IS 'Added by SF 2016-08-27.';


--
-- Name: fk_qeid_qem; Type: FK CONSTRAINT; Schema: monprog; Owner: -
--

ALTER TABLE ONLY quality_element_indicator_descriptor
    ADD CONSTRAINT fk_qeid_qem FOREIGN KEY (qem_id) REFERENCES public.quality_element(qem_id);



--
-- Name: FK_VerwerkingsVerslagParameter_VerwerkingsVerslag; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY "VerwerkingsVerslagParameter"
    ADD CONSTRAINT "FK_VerwerkingsVerslagParameter_VerwerkingsVerslag" FOREIGN KEY ("verwerkingsVerslagId") REFERENCES "VerwerkingsVerslag"(id) ON UPDATE CASCADE ON DELETE CASCADE;


--
-- Name: FK_VerwerkingsVerslagRegel_VerwerkingsVerslag; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY "VerwerkingsVerslagRegel"
    ADD CONSTRAINT "FK_VerwerkingsVerslagRegel_VerwerkingsVerslag" FOREIGN KEY ("verwerkingsVerslagId") REFERENCES "VerwerkingsVerslag"(id) ON UPDATE CASCADE ON DELETE CASCADE;


--
-- Name: FK_VerwerkingsVerslagRegel_VerwerkingsVerslagRegeloort; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY "VerwerkingsVerslagRegel"
    ADD CONSTRAINT "FK_VerwerkingsVerslagRegel_VerwerkingsVerslagRegeloort" FOREIGN KEY ("verwerkingsVerslagRegelSoortId") REFERENCES "VerwerkingsVerslagRegelSoort"(id);


--
-- Name: FK_VerwerkingsVerslag_Actie; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY "VerwerkingsVerslag"
    ADD CONSTRAINT "FK_VerwerkingsVerslag_Actie" FOREIGN KEY ("actieId") REFERENCES "Actie"(id);


--
-- Name: FK_VerwerkingsVerslag_VerwerkingsVerslagStatus; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY "VerwerkingsVerslag"
    ADD CONSTRAINT "FK_VerwerkingsVerslag_VerwerkingsVerslagStatus" FOREIGN KEY ("verwerkingsVerslagStatusId") REFERENCES "VerwerkingsVerslagStatus"(id);


--
-- Name: bronnen_chemische_stof_type_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY bronnen
    ADD CONSTRAINT bronnen_chemische_stof_type_fkey FOREIGN KEY (chs_id) REFERENCES chemische_stof_type(chs_id);


--
-- Name: bronnen_hydroobject_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY bronnen
    ADD CONSTRAINT bronnen_hydroobject_fkey FOREIGN KEY (hdo_id) REFERENCES hydro_object(hdo_id);


--
-- Name: bronnen_waarde_bepalings_methode_type_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY bronnen
    ADD CONSTRAINT bronnen_waarde_bepalings_methode_type_fkey FOREIGN KEY (wbpm_id) REFERENCES waarde_bepalings_methode_type(wbpm_id);


--
-- Name: bronnen_waarde_eenheid_type_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY bronnen
    ADD CONSTRAINT bronnen_waarde_eenheid_type_fkey FOREIGN KEY (eenh_id) REFERENCES eenheid_type(eenh_id);


--
-- Name: fk_43a_measures; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY sw_measure43_function
    ADD CONSTRAINT fk_43a_measures FOREIGN KEY (smee_id) REFERENCES swb_measures_43a(swee_id);


--
-- Name: fk_abstraction_point_hydro_object; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY gw_abstraction_point
    ADD CONSTRAINT fk_abstraction_point_hydro_object FOREIGN KEY (gasp_id) REFERENCES abstraction_point(asp_id);


--
-- Name: fk_abstraction_point_hydro_object; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY abstraction_point
    ADD CONSTRAINT fk_abstraction_point_hydro_object FOREIGN KEY (asp_id) REFERENCES hydro_object(hdo_id);


--
-- Name: fk_abstraction_point_rewab_type; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY gw_abstraction_point
    ADD CONSTRAINT fk_abstraction_point_rewab_type FOREIGN KEY (rewab_id) REFERENCES rewab_type(rwb_id);


--
-- Name: fk_abstraction_point_wbd; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY abstraction_point
    ADD CONSTRAINT fk_abstraction_point_wbd FOREIGN KEY (wbd_id) REFERENCES water_body(wbd_id);


--
-- Name: fk_acoc_info_stream_activity; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY activity_organisation_category
    ADD CONSTRAINT fk_acoc_info_stream_activity FOREIGN KEY (isac_id) REFERENCES info_stream_activity(isac_id);


--
-- Name: fk_acoc_organisation_category_type; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY activity_organisation_category
    ADD CONSTRAINT fk_acoc_organisation_category_type FOREIGN KEY (ocat_id) REFERENCES organisation_category_type(ocat_id);


--
-- Name: fk_art43b_art43b_type; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY swb_art43b_excemption
    ADD CONSTRAINT fk_art43b_art43b_type FOREIGN KEY (a43b_id) REFERENCES eu_article_43b_type(a43b_id);


--
-- Name: fk_art43b_swb; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY swb_art43b_excemption
    ADD CONSTRAINT fk_art43b_swb FOREIGN KEY (swb_id) REFERENCES surface_water_body(swb_id);


--
-- Name: fk_asp; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY gw_abstraction_point_status
    ADD CONSTRAINT fk_asp FOREIGN KEY (asp_id) REFERENCES abstraction_point(asp_id);


--
-- Name: fk_bio_observation_gedrag; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY bio_observation
    ADD CONSTRAINT fk_bio_observation_gedrag FOREIGN KEY (gedrag_id) REFERENCES BiologischKenmerk(id);


--
-- Name: fk_bio_observation_geslacht; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY bio_observation
    ADD CONSTRAINT fk_bio_observation_geslacht FOREIGN KEY (geslacht_id) REFERENCES BiologischKenmerk(id);


--
-- Name: fk_bio_observation_lengte_klasse; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY bio_observation
    ADD CONSTRAINT fk_bio_observation_lengte_klasse FOREIGN KEY (lengte_klasse_id) REFERENCES BiologischKenmerk(id);


--
-- Name: fk_bio_observation_levensstadium; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY bio_observation
    ADD CONSTRAINT fk_bio_observation_levensstadium FOREIGN KEY (levensstadium_id) REFERENCES BiologischKenmerk(id);


--
-- Name: fk_bio_observation_levensvorm; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY bio_observation
    ADD CONSTRAINT fk_bio_observation_levensvorm FOREIGN KEY (levensvorm_id) REFERENCES BiologischKenmerk(id);


--
-- Name: fk_bio_observation_observation; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY bio_observation
    ADD CONSTRAINT fk_bio_observation_observation FOREIGN KEY (obs_id) REFERENCES observation(obs_id);


--
-- Name: fk_bio_observation_verschijningsvorm; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY bio_observation
    ADD CONSTRAINT fk_bio_observation_verschijningsvorm FOREIGN KEY (verschijningsvorm_id) REFERENCES BiologischKenmerk(id);


--
-- Name: fk_ca_role_code; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY competent_authority_roles
    ADD CONSTRAINT fk_ca_role_code FOREIGN KEY (crc_id) REFERENCES ca_role_code(crc_id);


--
-- Name: fk_ca_role_code_lgr; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY ca_role_code
    ADD CONSTRAINT fk_ca_role_code_lgr FOREIGN KEY (lgr_id) REFERENCES legislation_reference_type(lgr_id);


--
-- Name: fk_chemische_stof_substance_element; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY substance_group_element
    ADD CONSTRAINT fk_chemische_stof_substance_element FOREIGN KEY (chs_id) REFERENCES chemische_stof_type(chs_id);


--
-- Name: fk_chemische_stof_type; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY chemical_exceedance
    ADD CONSTRAINT fk_chemische_stof_type FOREIGN KEY (chs_id) REFERENCES chemische_stof_type(chs_id);


--
-- Name: fk_chs; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY gw_pollutants
    ADD CONSTRAINT fk_chs FOREIGN KEY (chs_id) REFERENCES chemische_stof_type(chs_id);


--
-- Name: fk_cls_clsg; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY classification_type
    ADD CONSTRAINT fk_cls_clsg FOREIGN KEY (clsg_id) REFERENCES classification_group_type(clsg_id);


--
-- Name: fk_cls_id; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY gw_chemical_status
    ADD CONSTRAINT fk_cls_id FOREIGN KEY (clst_id) REFERENCES classification_type(cls_id);


--
-- Name: fk_cls_id; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY gw_swb_status
    ADD CONSTRAINT fk_cls_id FOREIGN KEY (cls_id) REFERENCES classification_type(cls_id);


--
-- Name: fk_clsg_id; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY wfd_qe_swtype
    ADD CONSTRAINT fk_clsg_id FOREIGN KEY (clsg_id) REFERENCES classification_group_type(clsg_id);


--
-- Name: fk_clsg_id; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY wfd_qe_gwtype
    ADD CONSTRAINT fk_clsg_id FOREIGN KEY (clsg_id) REFERENCES classification_group_type(clsg_id);


--
-- Name: fk_compartiment_type; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY monitored_compartiment
    ADD CONSTRAINT fk_compartiment_type FOREIGN KEY (cptm_id) REFERENCES compartiment_type(cptm_id);


--
-- Name: fk_competent_authority; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY competent_authority_roles
    ADD CONSTRAINT fk_competent_authority FOREIGN KEY (ore_id) REFERENCES competent_authority(ore_id);


--
-- Name: fk_competent_authority_namespace_type; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY competent_authority
    ADD CONSTRAINT fk_competent_authority_namespace_type FOREIGN KEY (namespace_id) REFERENCES namespace_type(ns_id);


--
-- Name: fk_competent_authority_organisatorische_eenheid; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY competent_authority
    ADD CONSTRAINT fk_competent_authority_organisatorische_eenheid FOREIGN KEY (ore_id) REFERENCES organisatorische_eenheid(ore_id);


--
-- Name: fk_confidence_level_type; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY gw_quantity_status
    ADD CONSTRAINT fk_confidence_level_type FOREIGN KEY (clt_id) REFERENCES domains.confidence_level_type(clt_id);


--
-- Name: fk_dlt; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY gw_monitoring_station
    ADD CONSTRAINT fk_dlt FOREIGN KEY (depth_sampled_id) REFERENCES eu_depth_level_type(dlt_id);


--
-- Name: fk_ecological_classification; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY sw_ecological_status
    ADD CONSTRAINT fk_ecological_classification FOREIGN KEY (swes_id) REFERENCES classification_type(cls_id);


--
-- Name: fk_emf; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY operational_activity_period
    ADD CONSTRAINT fk_emf FOREIGN KEY (emf_id) REFERENCES environmental_monitoring_facility(emf_id);


--
-- Name: fk_emf; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY monitoring_station
    ADD CONSTRAINT fk_emf FOREIGN KEY (mts_id) REFERENCES environmental_monitoring_facility(emf_id);


--
-- Name: fk_emf_measurement_regime_type; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY environmental_monitoring_facility
    ADD CONSTRAINT fk_emf_measurement_regime_type FOREIGN KEY (measurement_regime_id) REFERENCES measurement_regime_type(mmr_id);


--
-- Name: fk_emf_mnf; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY environmental_monitoring_facility
    ADD CONSTRAINT fk_emf_mnf FOREIGN KEY (emf_id) REFERENCES monitoring_feature(mnf_id);


--
-- Name: fk_emf_result_acquisition_source_type; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY environmental_monitoring_facility
    ADD CONSTRAINT fk_emf_result_acquisition_source_type FOREIGN KEY (result_acquisition_source_id) REFERENCES result_acquisition_source_type(ras_id);


--
-- Name: fk_emf_source; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY any_thematic_link
    ADD CONSTRAINT fk_emf_source FOREIGN KEY (emf_id) REFERENCES environmental_monitoring_facility(emf_id);


--
-- Name: fk_emf_specialised_emf_type; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY environmental_monitoring_facility
    ADD CONSTRAINT fk_emf_specialised_emf_type FOREIGN KEY (speciallised_emf_type_id) REFERENCES specialised_emf_type(semf_id);


--
-- Name: fk_emf_target; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY any_thematic_link
    ADD CONSTRAINT fk_emf_target FOREIGN KEY (related_emf_id) REFERENCES environmental_monitoring_facility(emf_id);


--
-- Name: fk_emn_lgl; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY environmental_monitoring_network
    ADD CONSTRAINT fk_emn_lgl FOREIGN KEY (organization_level_id) REFERENCES legislation_level_type(lgl_id);


--
-- Name: fk_emn_mnf; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY environmental_monitoring_network
    ADD CONSTRAINT fk_emn_mnf FOREIGN KEY (emn_id) REFERENCES monitoring_feature(mnf_id);


--
-- Name: fk_eu_monitoring_goal_type; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY sw_chemical_substance_status
    ADD CONSTRAINT fk_eu_monitoring_goal_type FOREIGN KEY (eumg_id) REFERENCES eu_monitoring_goal_type(eumg_id);


--
-- Name: fk_eu_monitoring_goal_type; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY sw_ecological_status
    ADD CONSTRAINT fk_eu_monitoring_goal_type FOREIGN KEY (eumg_id) REFERENCES eu_monitoring_goal_type(eumg_id);


--
-- Name: fk_eu_monitoring_goal_type; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY gw_chemical_status
    ADD CONSTRAINT fk_eu_monitoring_goal_type FOREIGN KEY (eumg_id) REFERENCES eu_monitoring_goal_type(eumg_id);


--
-- Name: fk_eumg_id; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY gw_quantity_status
    ADD CONSTRAINT fk_eumg_id FOREIGN KEY (eumg_id) REFERENCES eu_monitoring_goal_type(eumg_id);


--
-- Name: fk_excemption_mechanism; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY swb_excemption_mechanism_44
    ADD CONSTRAINT fk_excemption_mechanism FOREIGN KEY (exme_id) REFERENCES excemption_mechanism_type(exme_id);


--
-- Name: fk_faq_thema_id; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY faq_item
    ADD CONSTRAINT fk_faq_thema_id FOREIGN KEY (faq_thema_id) REFERENCES faq_thema(faq_thema_id);


--
-- Name: fk_fim_emf; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY env_mon_facil_in_mngmt_reg_or_restr_zone
    ADD CONSTRAINT fk_fim_emf FOREIGN KEY (emf_id) REFERENCES environmental_monitoring_facility(emf_id);


--
-- Name: fk_fim_mrz; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY env_mon_facil_in_mngmt_reg_or_restr_zone
    ADD CONSTRAINT fk_fim_mrz FOREIGN KEY (mrz_id) REFERENCES management_regulation_or_restriction_zone(mrz_id);


--
-- Name: fk_finance_type; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY measure_finance
    ADD CONSTRAINT fk_finance_type FOREIGN KEY (mft_id) REFERENCES measure_finance_type(mtf_id);


--
-- Name: fk_freq_uom; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY quality_element
    ADD CONSTRAINT fk_freq_uom FOREIGN KEY (frequency_uom_id) REFERENCES eenheid_type(eenh_id);


--
-- Name: fk_from_hdo; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY related_hydro_object
    ADD CONSTRAINT fk_from_hdo FOREIGN KEY (from_hdo) REFERENCES hydro_object(hdo_id);


--
-- Name: fk_from_mno; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY related_monitoring_object
    ADD CONSTRAINT fk_from_mno FOREIGN KEY (from_mno) REFERENCES monitoring_object(mno_id);


--
-- Name: fk_gcep_gwb_chemical_exemption; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY gwb_chem_exemp_pollutant
    ADD CONSTRAINT fk_gcep_gwb_chemical_exemption FOREIGN KEY (gwce_id) REFERENCES gwb_chemical_exemption(gwce_id);


--
-- Name: fk_gcep_gwb_opt_id; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY gwb_chem_exemp_pollutant
    ADD CONSTRAINT fk_gcep_gwb_opt_id FOREIGN KEY (opt_id) REFERENCES observed_property_type(opt_id);


--
-- Name: fk_geo_reference_process_monitoring_object; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY geo_reference_process
    ADD CONSTRAINT fk_geo_reference_process_monitoring_object FOREIGN KEY (mno_id) REFERENCES monitoring_object(mno_id);


--
-- Name: fk_geo_reference_process_plaatsbepalingsapparaat_type; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY geo_reference_process
    ADD CONSTRAINT fk_geo_reference_process_plaatsbepalingsapparaat_type FOREIGN KEY (plaatsbep_app_id) REFERENCES plaatsbepalingsapparaat_type(pba_id);


--
-- Name: fk_gms; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY monitoring_use
    ADD CONSTRAINT fk_gms FOREIGN KEY (gms_id) REFERENCES monitoring_station(mts_id);


--
-- Name: fk_gn2kcs_cls; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY gw_n2000_status
    ADD CONSTRAINT fk_gn2kcs_cls FOREIGN KEY (cls_id) REFERENCES classification_type(cls_id);


--
-- Name: fk_gn2kcs_gwsy; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY gw_n2000_status
    ADD CONSTRAINT fk_gn2kcs_gwsy FOREIGN KEY (gwsy) REFERENCES gwb_yearly_status(gys_id);


--
-- Name: fk_gn2kcs_opt; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY gw_n2000_status
    ADD CONSTRAINT fk_gn2kcs_opt FOREIGN KEY (opt_id) REFERENCES observed_property_type(opt_id);


--
-- Name: fk_gn2kcs_wpa; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY gw_n2000_status
    ADD CONSTRAINT fk_gn2kcs_wpa FOREIGN KEY (wpa_id) REFERENCES wfd_protected_area(wpa_id);


--
-- Name: fk_gomu_gw_monitoring_station; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY gw_mon_stat_other_mon_use
    ADD CONSTRAINT fk_gomu_gw_monitoring_station FOREIGN KEY (gms_id) REFERENCES gw_monitoring_station(gms_id);


--
-- Name: fk_gomu_other_monitoring_use_type; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY gw_mon_stat_other_mon_use
    ADD CONSTRAINT fk_gomu_other_monitoring_use_type FOREIGN KEY (omut_id) REFERENCES other_monitoring_use_type(omut_id);


--
-- Name: fk_gpg_eenheid_type; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY gw_pressures_preventing_good_status
    ADD CONSTRAINT fk_gpg_eenheid_type FOREIGN KEY (percentage_failure_uom_id) REFERENCES eenheid_type(eenh_id);


--
-- Name: fk_gpg_gw_aggregated_pressure_type; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY gw_pressures_preventing_good_status
    ADD CONSTRAINT fk_gpg_gw_aggregated_pressure_type FOREIGN KEY (gwap_id) REFERENCES gw_aggregated_pressure_type(gwap_id);


--
-- Name: fk_gpg_river_basin_management_plan; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY gw_pressures_preventing_good_status
    ADD CONSTRAINT fk_gpg_river_basin_management_plan FOREIGN KEY (rbmp_id) REFERENCES river_basin_management_plan(rbmp_id);


--
-- Name: fk_gprm_basic_measure113a_type; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY gw_pressure_requiring_supp_add_measures
    ADD CONSTRAINT fk_gprm_basic_measure113a_type FOREIGN KEY (bma_id) REFERENCES basic_measure113a_type(bma_id);


--
-- Name: fk_gprm_gw_pressure_type; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY gw_pressure_requiring_supp_add_measures
    ADD CONSTRAINT fk_gprm_gw_pressure_type FOREIGN KEY (gprs_id) REFERENCES gw_pressure_type(gprs_id);


--
-- Name: fk_gprm_gw_pressures_preventing_good_status; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY gw_pressure_requiring_supp_add_measures
    ADD CONSTRAINT fk_gprm_gw_pressures_preventing_good_status FOREIGN KEY (gpg_id) REFERENCES gw_pressures_preventing_good_status(gpg_id);


--
-- Name: fk_gprm_other_basic_measure113b_type; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY gw_pressure_requiring_supp_add_measures
    ADD CONSTRAINT fk_gprm_other_basic_measure113b_type FOREIGN KEY (obmb_id) REFERENCES other_basic_measure113b_type(obmb_id);


--
-- Name: fk_gqe_ground_water_body; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY gwb_quantitative_exemption
    ADD CONSTRAINT fk_gqe_ground_water_body FOREIGN KEY (gwb_id) REFERENCES ground_water_body(gwb_id);


--
-- Name: fk_gqe_objectives_exemption_type; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY gwb_quantitative_exemption
    ADD CONSTRAINT fk_gqe_objectives_exemption_type FOREIGN KEY (obex_id) REFERENCES objectives_exemption_type(obex_id);


--
-- Name: fk_grcf; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY gwb_reason4chemical_failure
    ADD CONSTRAINT fk_grcf FOREIGN KEY (grcf_id) REFERENCES gw_reason4chemical_failure(grcf_id);


--
-- Name: fk_ground_water_body_depth_range_type; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY ground_water_body
    ADD CONSTRAINT fk_ground_water_body_depth_range_type FOREIGN KEY (depth_range_id) REFERENCES depth_range_type(dpr_id);


--
-- Name: fk_ground_water_body_geological_formation_type; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY ground_water_body
    ADD CONSTRAINT fk_ground_water_body_geological_formation_type FOREIGN KEY (geological_formation_id) REFERENCES geological_formation_type(gfm_id);


--
-- Name: fk_ground_water_body_gw_vertical_orientation_type; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY ground_water_body
    ADD CONSTRAINT fk_ground_water_body_gw_vertical_orientation_type FOREIGN KEY (vertical_orientation_id) REFERENCES gw_vertical_orientation_type(gvo_id);


--
-- Name: fk_ground_water_body_reason_change_type; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY ground_water_body
    ADD CONSTRAINT fk_ground_water_body_reason_change_type FOREIGN KEY (rct_id) REFERENCES reason_change_type(rct_id);


--
-- Name: fk_ground_water_body_substrate_type; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY ground_water_body
    ADD CONSTRAINT fk_ground_water_body_substrate_type FOREIGN KEY (substrate_id) REFERENCES substrate_type(sub_id);


--
-- Name: fk_group_substance_element; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY substance_group_element
    ADD CONSTRAINT fk_group_substance_element FOREIGN KEY (ssge_id) REFERENCES substance_group(ssg_id);


--
-- Name: fk_grqf; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY gwb_reason4quantity_failure
    ADD CONSTRAINT fk_grqf FOREIGN KEY (grqf_id) REFERENCES gw_reason4quantity_failure(grqf_id);


--
-- Name: fk_grsm_gw_pressure_requiring_supp_add_measures; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY gw_required_supp_measure
    ADD CONSTRAINT fk_grsm_gw_pressure_requiring_supp_add_measures FOREIGN KEY (gprm_id) REFERENCES gw_pressure_requiring_supp_add_measures(gprm_id);


--
-- Name: fk_grsm_supp_add_measure_nl_type; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY gw_required_supp_measure
    ADD CONSTRAINT fk_grsm_supp_add_measure_nl_type FOREIGN KEY (smnl_id) REFERENCES supp_add_measure_type(smnl_id);


--
-- Name: fk_gw_chemical_status_gwb_yearly_status; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY gw_chemical_status
    ADD CONSTRAINT fk_gw_chemical_status_gwb_yearly_status FOREIGN KEY (gys_id) REFERENCES gwb_yearly_status(gys_id);


--
-- Name: fk_gw_pressure_type_driver; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY gw_pressure_type_driver
    ADD CONSTRAINT fk_gw_pressure_type_driver FOREIGN KEY (driver_id) REFERENCES domains.drivers(driver_id);


--
-- Name: fk_gw_pressure_type_sprs; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY gw_pressure_type_driver
    ADD CONSTRAINT fk_gw_pressure_type_sprs FOREIGN KEY (gprs_id) REFERENCES gw_pressure_type(gprs_id);


--
-- Name: fk_gw_status_type; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY gw_abstraction_point_status
    ADD CONSTRAINT fk_gw_status_type FOREIGN KEY (gwst_id) REFERENCES classification_type(cls_id);


--
-- Name: fk_gw_test_value_norm_value; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY gw_test_value
    ADD CONSTRAINT fk_gw_test_value_norm_value FOREIGN KEY (nrmv_id) REFERENCES norm_value(nrmv_id);


--
-- Name: fk_gw_testing_conclusion_eumg; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY gw_testing_conclusion
    ADD CONSTRAINT fk_gw_testing_conclusion_eumg FOREIGN KEY (eumg_id) REFERENCES eu_monitoring_goal_type(eumg_id);


--
-- Name: fk_gw_testing_conclusion_gwb_yearly_status; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY gw_testing_conclusion
    ADD CONSTRAINT fk_gw_testing_conclusion_gwb_yearly_status FOREIGN KEY (gys_id) REFERENCES gwb_yearly_status(gys_id);


--
-- Name: fk_gw_testing_conclusion_observation; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY gw_testing_conclusion
    ADD CONSTRAINT fk_gw_testing_conclusion_observation FOREIGN KEY (gtcc_id) REFERENCES observation(obs_id);


--
-- Name: fk_gwb_avg_depth_uom; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY ground_water_body
    ADD CONSTRAINT fk_gwb_avg_depth_uom FOREIGN KEY (average_depth_uom_id) REFERENCES eenheid_type(eenh_id);


--
-- Name: fk_gwb_avg_thickness_uom; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY ground_water_body
    ADD CONSTRAINT fk_gwb_avg_thickness_uom FOREIGN KEY (average_thickness_uom_id) REFERENCES eenheid_type(eenh_id);


--
-- Name: fk_gwb_capacity_uom; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY ground_water_body
    ADD CONSTRAINT fk_gwb_capacity_uom FOREIGN KEY (capacity_uom_id) REFERENCES eenheid_type(eenh_id);


--
-- Name: fk_gwb_pressure_gwbp; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY gwb_pressure_impact
    ADD CONSTRAINT fk_gwb_pressure_gwbp FOREIGN KEY (gwbp_id) REFERENCES gwb_pressure(gwbp_id);


--
-- Name: fk_gwb_pressure_impact; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY gwb_pressure_impact
    ADD CONSTRAINT fk_gwb_pressure_impact FOREIGN KEY (impact_id) REFERENCES domains.impacts(impact_id);


--
-- Name: fk_gwb_yearly_status; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY gw_quantity_status
    ADD CONSTRAINT fk_gwb_yearly_status FOREIGN KEY (gys_id) REFERENCES gwb_yearly_status(gys_id);


--
-- Name: fk_gwb_yearly_status_ground_water_body; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY gwb_yearly_status
    ADD CONSTRAINT fk_gwb_yearly_status_ground_water_body FOREIGN KEY (gwb_id) REFERENCES ground_water_body(gwb_id);


--
-- Name: fk_gwce_ground_water_body; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY gwb_chemical_exemption
    ADD CONSTRAINT fk_gwce_ground_water_body FOREIGN KEY (gwb_id) REFERENCES ground_water_body(gwb_id);


--
-- Name: fk_gwce_objectives_exemption_type; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY gwb_chemical_exemption
    ADD CONSTRAINT fk_gwce_objectives_exemption_type FOREIGN KEY (obex_id) REFERENCES objectives_exemption_type(obex_id);


--
-- Name: fk_gwcs_confidence_level_type; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY gw_chemical_status
    ADD CONSTRAINT fk_gwcs_confidence_level_type FOREIGN KEY (clt_id) REFERENCES domains.confidence_level_type(clt_id);


--
-- Name: fk_gwpr_ground_water_body; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY gwb_pressure
    ADD CONSTRAINT fk_gwpr_ground_water_body FOREIGN KEY (gwb_id) REFERENCES ground_water_body(gwb_id);


--
-- Name: fk_gwpr_gw_pressure_type; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY gwb_pressure
    ADD CONSTRAINT fk_gwpr_gw_pressure_type FOREIGN KEY (gprs_id) REFERENCES gw_pressure_type(gprs_id);


--
-- Name: fk_gwpr_relevance; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY gwb_pressure
    ADD CONSTRAINT fk_gwpr_relevance FOREIGN KEY (prr_id) REFERENCES pressure_relevance_type(prr_id);


--
-- Name: fk_gwpt_pressure_category_type; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY gw_pressure_type
    ADD CONSTRAINT fk_gwpt_pressure_category_type FOREIGN KEY (pressure_category_id) REFERENCES pressure_category_type(pcat_id);


--
-- Name: fk_gwsy; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY gw_abstraction_point_status
    ADD CONSTRAINT fk_gwsy FOREIGN KEY (gwsy_id) REFERENCES gwb_yearly_status(gys_id);


--
-- Name: fk_gwsy_id; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY gw_swb_status
    ADD CONSTRAINT fk_gwsy_id FOREIGN KEY (gwsy) REFERENCES gwb_yearly_status(gys_id);


--
-- Name: fk_gys; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY gw_pollutants
    ADD CONSTRAINT fk_gys FOREIGN KEY (gys_id) REFERENCES gwb_yearly_status(gys_id);


--
-- Name: fk_gys; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY gwb_reason4chemical_failure
    ADD CONSTRAINT fk_gys FOREIGN KEY (gys_id) REFERENCES gwb_yearly_status(gys_id);


--
-- Name: fk_gys; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY gwb_reason4quantity_failure
    ADD CONSTRAINT fk_gys FOREIGN KEY (gys_id) REFERENCES gwb_yearly_status(gys_id);


--
-- Name: fk_hdo; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY planned_feature_monitoring
    ADD CONSTRAINT fk_hdo FOREIGN KEY (hdo_id) REFERENCES hydro_object(hdo_id);


--
-- Name: fk_hdo_identfiers_hydro_object; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY hdo_identfiers
    ADD CONSTRAINT fk_hdo_identfiers_hydro_object FOREIGN KEY (hdo_id) REFERENCES hydro_object(hdo_id);


--
-- Name: fk_hdo_identfiers_namespace_type; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY hdo_identfiers
    ADD CONSTRAINT fk_hdo_identfiers_namespace_type FOREIGN KEY (namespace_id) REFERENCES namespace_type(ns_id);


--
-- Name: fk_hdo_names_hydro_object; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY hdo_names
    ADD CONSTRAINT fk_hdo_names_hydro_object FOREIGN KEY (hdo_id) REFERENCES hydro_object(hdo_id);


--
-- Name: fk_hydro_object_inspire_id_namespace_type; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY hydro_object
    ADD CONSTRAINT fk_hydro_object_inspire_id_namespace_type FOREIGN KEY (inspire_id_namespace) REFERENCES namespace_type(ns_id);


--
-- Name: fk_hydro_object_wkr_version; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY hydro_object
    ADD CONSTRAINT fk_hydro_object_wkr_version FOREIGN KEY (wkrv_id) REFERENCES wkr_version(wkrv_id);


--
-- Name: fk_initiative_org_cat_id; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY supp_add_measure_type
    ADD CONSTRAINT fk_initiative_org_cat_id FOREIGN KEY (initiative_party_ocat_id) REFERENCES organisation_category_type(ocat_id);


--
-- Name: fk_int_rbd; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY river_basin_disrict
    ADD CONSTRAINT fk_int_rbd FOREIGN KEY (international_rbd) REFERENCES river_basin_disrict(rbd_id);


--
-- Name: fk_isac_information_stream; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY info_stream_activity
    ADD CONSTRAINT fk_isac_information_stream FOREIGN KEY (ims_id) REFERENCES information_stream(ims_id);


--
-- Name: fk_islb_information_stream; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY info_stream_legal_background
    ADD CONSTRAINT fk_islb_information_stream FOREIGN KEY (ims_id) REFERENCES information_stream(ims_id);


--
-- Name: fk_lgr; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY mzc_legal_basis
    ADD CONSTRAINT fk_lgr FOREIGN KEY (lgr_id) REFERENCES legislation_reference_type(lgr_id);


--
-- Name: fk_lgr_legislation_level_type; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY legislation_reference_type
    ADD CONSTRAINT fk_lgr_legislation_level_type FOREIGN KEY (legislation_level_id) REFERENCES legislation_level_type(lgl_id);


--
-- Name: fk_ligt_in_mrz; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY environmental_monitoring_facility
    ADD CONSTRAINT fk_ligt_in_mrz FOREIGN KEY (ligt_in_mrz_id) REFERENCES management_regulation_or_restriction_zone(mrz_id);


--
-- Name: fk_low_eenh; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY sample
    ADD CONSTRAINT fk_low_eenh FOREIGN KEY (lower_depth_uom_id) REFERENCES eenheid_type(eenh_id);


--
-- Name: fk_lowerbound_limiet; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY norm_value
    ADD CONSTRAINT fk_lowerbound_limiet FOREIGN KEY (lowerbound_limit_symbol_id) REFERENCES bepaling_grens_type(bpg_id);


--
-- Name: fk_measure43; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY sw_measure43_function
    ADD CONSTRAINT fk_measure43 FOREIGN KEY (me43_id) REFERENCES sw_measure43_nl_type(me43_id);


--
-- Name: fk_mfp_mnf; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY monitoring_feature_positioning_method
    ADD CONSTRAINT fk_mfp_mnf FOREIGN KEY (mnf_id) REFERENCES monitoring_feature(mnf_id);


--
-- Name: fk_mfp_pba; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY monitoring_feature_positioning_method
    ADD CONSTRAINT fk_mfp_pba FOREIGN KEY (pba_id) REFERENCES plaatsbepalingsapparaat_type(pba_id);


--
-- Name: fk_mfr_mnf; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY monitoring_feature_report_to
    ADD CONSTRAINT fk_mfr_mnf FOREIGN KEY (mnf_id) REFERENCES monitoring_feature(mnf_id);


--
-- Name: fk_mmef_eu_fund_type; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY monitored_measure_eu_fund
    ADD CONSTRAINT fk_mmef_eu_fund_type FOREIGN KEY (euf_id) REFERENCES eu_fund_type(euf_id);


--
-- Name: fk_mmef_monitored_measure; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY monitored_measure_eu_fund
    ADD CONSTRAINT fk_mmef_monitored_measure FOREIGN KEY (mtm_id) REFERENCES monitored_measure(mtm_id);


--
-- Name: fk_mmpa_mtm; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY measure_per_man_protected_area
    ADD CONSTRAINT fk_mmpa_mtm FOREIGN KEY (mtm_id) REFERENCES monitored_measure(mtm_id);


--
-- Name: fk_mmpa_wpa; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY measure_per_man_protected_area
    ADD CONSTRAINT fk_mmpa_wpa FOREIGN KEY (wpa_id) REFERENCES wfd_protected_area(wpa_id);


--
-- Name: fk_mmpap_apt; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY measure_per_abstraction_point
    ADD CONSTRAINT fk_mmpap_apt FOREIGN KEY (asp_id) REFERENCES abstraction_point(asp_id);


--
-- Name: fk_mmpap_mtm; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY measure_per_abstraction_point
    ADD CONSTRAINT fk_mmpap_mtm FOREIGN KEY (mtm_id) REFERENCES monitored_measure(mtm_id);


--
-- Name: fk_mmz_mrz; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY measure_per_man_reg_or_restr_zone
    ADD CONSTRAINT fk_mmz_mrz FOREIGN KEY (mrz_id) REFERENCES management_regulation_or_restriction_zone(mrz_id);


--
-- Name: fk_mmz_mtm; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY measure_per_man_reg_or_restr_zone
    ADD CONSTRAINT fk_mmz_mtm FOREIGN KEY (mtm_id) REFERENCES monitored_measure(mtm_id);


--
-- Name: fk_mnf; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY mnf_parameter
    ADD CONSTRAINT fk_mnf FOREIGN KEY (mnf_id) REFERENCES monitoring_feature(mnf_id);


--
-- Name: fk_mnf_mno; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY monitoring_feature
    ADD CONSTRAINT fk_mnf_mno FOREIGN KEY (mnf_id) REFERENCES monitoring_object(mno_id);


--
-- Name: fk_mnf_source; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY related_sampling_feature
    ADD CONSTRAINT fk_mnf_source FOREIGN KEY (mnf_id_source) REFERENCES monitoring_feature(mnf_id);


--
-- Name: fk_mnf_target; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY related_sampling_feature
    ADD CONSTRAINT fk_mnf_target FOREIGN KEY (mnf_id_target) REFERENCES monitoring_feature(mnf_id);


--
-- Name: fk_mnfp_value_uom; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY mnf_parameter
    ADD CONSTRAINT fk_mnfp_value_uom FOREIGN KEY (value_uom_id) REFERENCES eenheid_type(eenh_id);


--
-- Name: fk_mno_narrower; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY monitoring_object_hierarchy
    ADD CONSTRAINT fk_mno_narrower FOREIGN KEY (mno_id_narrower) REFERENCES monitoring_object(mno_id);


--
-- Name: fk_mno_supersedes; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY monitoring_object_genealogy
    ADD CONSTRAINT fk_mno_supersedes FOREIGN KEY (mno_id_supersedes) REFERENCES monitoring_object(mno_id);


--
-- Name: fk_moi_monitoring_object; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY monitoring_object_other_ids
    ADD CONSTRAINT fk_moi_monitoring_object FOREIGN KEY (mno_id) REFERENCES monitoring_object(mno_id);


--
-- Name: fk_moi_ore; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY monitoring_object_other_ids
    ADD CONSTRAINT fk_moi_ore FOREIGN KEY (hydro_id_ore_id) REFERENCES organisatorische_eenheid(ore_id);


--
-- Name: fk_monitored_measure_mtmid; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY measure_progress_completed
    ADD CONSTRAINT fk_monitored_measure_mtmid FOREIGN KEY (mtm_id) REFERENCES monitored_measure(mtm_id);


--
-- Name: fk_monitored_measure_report_version; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY monitored_measure
    ADD CONSTRAINT fk_monitored_measure_report_version FOREIGN KEY (rpv_id) REFERENCES report_version(rpv_id);


--
-- Name: fk_monitoring_object; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY monitored_compartiment
    ADD CONSTRAINT fk_monitoring_object FOREIGN KEY (mno_id) REFERENCES monitoring_object(mno_id);


--
-- Name: fk_monitoring_object; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY program_monitoring_object
    ADD CONSTRAINT fk_monitoring_object FOREIGN KEY (object_mno_id) REFERENCES monitoring_object(mno_id);


--
-- Name: fk_monitoring_object_hoedanigheid; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY monitoring_object
    ADD CONSTRAINT fk_monitoring_object_hoedanigheid FOREIGN KEY (primary_geodetic_reference_id) REFERENCES hoedanigheid_type(hdh_id);


--
-- Name: fk_monitoring_object_smpl_id; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY sample
    ADD CONSTRAINT fk_monitoring_object_smpl_id FOREIGN KEY (smpl_id) REFERENCES monitoring_object(mno_id);


--
-- Name: fk_monitoring_object_wkr_version; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY monitoring_object
    ADD CONSTRAINT fk_monitoring_object_wkr_version FOREIGN KEY (wkrv_id) REFERENCES wkr_version(wkrv_id);


--
-- Name: fk_moqe_monitoring_object; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY monitoring_object_quality_element
    ADD CONSTRAINT fk_moqe_monitoring_object FOREIGN KEY (mno_id) REFERENCES monitoring_object(mno_id);


--
-- Name: fk_moqe_quality_element; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY monitoring_object_quality_element
    ADD CONSTRAINT fk_moqe_quality_element FOREIGN KEY (qem_id) REFERENCES quality_element(qem_id);


--
-- Name: fk_mrz_environmental_domain_code; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY management_regulation_or_restriction_zone
    ADD CONSTRAINT fk_mrz_environmental_domain_code FOREIGN KEY (environmental_domain_id) REFERENCES environmental_domain_code(emd_id);


--
-- Name: fk_mrz_hydro_object; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY management_regulation_or_restriction_zone
    ADD CONSTRAINT fk_mrz_hydro_object FOREIGN KEY (mrz_id) REFERENCES hydro_object(hdo_id);


--
-- Name: fk_mrz_mzc; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY management_regulation_or_restriction_zone
    ADD CONSTRAINT fk_mrz_mzc FOREIGN KEY (mrz_collection_id) REFERENCES management_regulation_or_restriction_zone_collection(mzc_id);


--
-- Name: fk_mrz_zone_type_code; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY management_regulation_or_restriction_zone
    ADD CONSTRAINT fk_mrz_zone_type_code FOREIGN KEY (specialised_zone_type_id) REFERENCES zone_type_code(ztc_id);


--
-- Name: fk_mrzc_namespace_type; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY management_regulation_or_restriction_zone_collection
    ADD CONSTRAINT fk_mrzc_namespace_type FOREIGN KEY (inspire_id_namespace_id) REFERENCES namespace_type(ns_id);


--
-- Name: fk_mrzc_wkr_version; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY management_regulation_or_restriction_zone_collection
    ADD CONSTRAINT fk_mrzc_wkr_version FOREIGN KEY (wkrv_id) REFERENCES wkr_version(wkrv_id);


--
-- Name: fk_msf_mtm; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY measure_finance
    ADD CONSTRAINT fk_msf_mtm FOREIGN KEY (mtm_id) REFERENCES monitored_measure(mtm_id);


--
-- Name: fk_msp_mst; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY measure_progress
    ADD CONSTRAINT fk_msp_mst FOREIGN KEY (mst_id) REFERENCES measure_status_type(mst_id);


--
-- Name: fk_msp_mtm; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY measure_progress
    ADD CONSTRAINT fk_msp_mtm FOREIGN KEY (mtm_id) REFERENCES monitored_measure(mtm_id);


--
-- Name: fk_mtm_competent_authority; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY monitored_measure
    ADD CONSTRAINT fk_mtm_competent_authority FOREIGN KEY (prime_competent_authority_id) REFERENCES competent_authority(ore_id);


--
-- Name: fk_mtm_level_of_measure_type; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY monitored_measure
    ADD CONSTRAINT fk_mtm_level_of_measure_type FOREIGN KEY (level_of_measure_id) REFERENCES level_of_area_type(loa_id);


--
-- Name: fk_mtm_monitored_measure; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY monitored_measure
    ADD CONSTRAINT fk_mtm_monitored_measure FOREIGN KEY (derived_from_measure_id) REFERENCES monitored_measure(mtm_id);


--
-- Name: fk_mts; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY gw_monitoring_station
    ADD CONSTRAINT fk_mts FOREIGN KEY (gms_id) REFERENCES monitoring_station(mts_id);


--
-- Name: fk_mtt; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY monitoring_use
    ADD CONSTRAINT fk_mtt FOREIGN KEY (mtt_id) REFERENCES eu_monitoring_type(mtt_id);


--
-- Name: fk_mzc; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY mzc_legal_basis
    ADD CONSTRAINT fk_mzc FOREIGN KEY (mzc_id) REFERENCES management_regulation_or_restriction_zone_collection(mzc_id);


--
-- Name: fk_nbl_concentration_uom; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY natural_background_levels
    ADD CONSTRAINT fk_nbl_concentration_uom FOREIGN KEY (concentration_uom_id) REFERENCES eenheid_type(eenh_id);


--
-- Name: fk_nbl_ground_water_body; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY natural_background_levels
    ADD CONSTRAINT fk_nbl_ground_water_body FOREIGN KEY (gwb_id) REFERENCES ground_water_body(gwb_id);


--
-- Name: fk_nbl_observed_property_type; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY natural_background_levels
    ADD CONSTRAINT fk_nbl_observed_property_type FOREIGN KEY (opt_id) REFERENCES observed_property_type(opt_id);


--
-- Name: fk_norm_feature_hydro_object; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY norm_feature
    ADD CONSTRAINT fk_norm_feature_hydro_object FOREIGN KEY (hdo_id) REFERENCES hydro_object(hdo_id);


--
-- Name: fk_norm_feature_norm; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY norm_feature
    ADD CONSTRAINT fk_norm_feature_norm FOREIGN KEY (nrm_id) REFERENCES norm(nrm_id);


--
-- Name: fk_norm_groep_type_norm_kader_type; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY norm_groep_type
    ADD CONSTRAINT fk_norm_groep_type_norm_kader_type FOREIGN KEY (nmkd_id) REFERENCES norm_kader_type(nmkd_id);


--
-- Name: fk_norm_hulp_mapping_chs; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY norm_hulp_mapping
    ADD CONSTRAINT fk_norm_hulp_mapping_chs FOREIGN KEY (chs_id) REFERENCES chemische_stof_type(chs_id);


--
-- Name: fk_norm_hulp_mapping_cptm; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY norm_hulp_mapping
    ADD CONSTRAINT fk_norm_hulp_mapping_cptm FOREIGN KEY (cptm_id) REFERENCES compartiment_type(cptm_id);


--
-- Name: fk_norm_hulp_mapping_eenh; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY norm_hulp_mapping
    ADD CONSTRAINT fk_norm_hulp_mapping_eenh FOREIGN KEY (eenh_id) REFERENCES eenheid_type(eenh_id);


--
-- Name: fk_norm_hulp_mapping_grh; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY norm_hulp_mapping
    ADD CONSTRAINT fk_norm_hulp_mapping_grh FOREIGN KEY (grh_id) REFERENCES grootheid_type(grh_id);


--
-- Name: fk_norm_hulp_mapping_hdh; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY norm_hulp_mapping
    ADD CONSTRAINT fk_norm_hulp_mapping_hdh FOREIGN KEY (hdh_id) REFERENCES hoedanigheid_type(hdh_id);


--
-- Name: fk_norm_hulp_mapping_opt; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY norm_hulp_mapping
    ADD CONSTRAINT fk_norm_hulp_mapping_opt FOREIGN KEY (opt_id) REFERENCES observed_property_type(opt_id);


--
-- Name: fk_norm_hulp_mapping_typ; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY norm_hulp_mapping
    ADD CONSTRAINT fk_norm_hulp_mapping_typ FOREIGN KEY (typ_id) REFERENCES typering_type(typ_id);


--
-- Name: fk_norm_hulp_mapping_wbm; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY norm_hulp_mapping
    ADD CONSTRAINT fk_norm_hulp_mapping_wbm FOREIGN KEY (wbm_id) REFERENCES waarde_bewerkings_methode_type(wbm_id);


--
-- Name: fk_norm_level_of_area_type; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY norm
    ADD CONSTRAINT fk_norm_level_of_area_type FOREIGN KEY (defined_at_level_id) REFERENCES level_of_area_type(loa_id);


--
-- Name: fk_norm_norm_groep_type; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY norm
    ADD CONSTRAINT fk_norm_norm_groep_type FOREIGN KEY (norm_groep_id) REFERENCES norm_groep_type(nmgp_id);


--
-- Name: fk_norm_observed_property_type; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY norm
    ADD CONSTRAINT fk_norm_observed_property_type FOREIGN KEY (observed_property) REFERENCES observed_property_type(opt_id);


--
-- Name: fk_norm_wkr_version; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY norm
    ADD CONSTRAINT fk_norm_wkr_version FOREIGN KEY (wkrv_id) REFERENCES wkr_version(wkrv_id);


--
-- Name: fk_normpakket_norm_groep_type; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY normpakket
    ADD CONSTRAINT fk_normpakket_norm_groep_type FOREIGN KEY (norm_groep_id) REFERENCES norm_groep_type(nmgp_id);


--
-- Name: fk_normpakket_norm_kader_type; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY normpakket
    ADD CONSTRAINT fk_normpakket_norm_kader_type FOREIGN KEY (norm_kader_id) REFERENCES norm_kader_type(nmkd_id);


--
-- Name: fk_normwaarde_compartiment_type; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY norm_value
    ADD CONSTRAINT fk_normwaarde_compartiment_type FOREIGN KEY (cptm_id) REFERENCES compartiment_type(cptm_id);


--
-- Name: fk_normwaarde_eenheid_type; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY norm_value
    ADD CONSTRAINT fk_normwaarde_eenheid_type FOREIGN KEY (lowerbound_uom_id) REFERENCES eenheid_type(eenh_id);


--
-- Name: fk_normwaarde_norm; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY norm_value
    ADD CONSTRAINT fk_normwaarde_norm FOREIGN KEY (nrm_id) REFERENCES norm(nrm_id);


--
-- Name: fk_normwaarde_norm_klasse; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY norm_value
    ADD CONSTRAINT fk_normwaarde_norm_klasse FOREIGN KEY (norm_klasse_id) REFERENCES classification_type(cls_id);


--
-- Name: fk_ns_id_namespace_type; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY competentauthority_namespacetype
    ADD CONSTRAINT fk_ns_id_namespace_type FOREIGN KEY (ns_id) REFERENCES namespace_type(ns_id);


--
-- Name: fk_nwf_emf; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY network_facility
    ADD CONSTRAINT fk_nwf_emf FOREIGN KEY (emf_id) REFERENCES environmental_monitoring_facility(emf_id);


--
-- Name: fk_nwf_emn; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY network_facility
    ADD CONSTRAINT fk_nwf_emn FOREIGN KEY (emn_id) REFERENCES environmental_monitoring_network(emn_id);


--
-- Name: fk_object_group; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY object_group_element
    ADD CONSTRAINT fk_object_group FOREIGN KEY (ojg_id) REFERENCES object_group(ojg_id);


--
-- Name: fk_object_type; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY object_group_element
    ADD CONSTRAINT fk_object_type FOREIGN KEY (obj_id) REFERENCES object_type(obj_id);


--
-- Name: fk_obp_accreditation_org; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY observation_process
    ADD CONSTRAINT fk_obp_accreditation_org FOREIGN KEY (accreditation_org_id) REFERENCES organisatorische_eenheid(ore_id);


--
-- Name: fk_obp_accreditation_org; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY observation_process_copy_dietmar
    ADD CONSTRAINT fk_obp_accreditation_org FOREIGN KEY (accreditation_org_id) REFERENCES organisatorische_eenheid(ore_id);


--
-- Name: fk_obp_analytical_technique; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY observation_process
    ADD CONSTRAINT fk_obp_analytical_technique FOREIGN KEY (analytical_technique_id) REFERENCES domains.waardebepalingstechniek(wbpt_id);


--
-- Name: fk_obp_analytical_technique; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY observation_process_copy_dietmar
    ADD CONSTRAINT fk_obp_analytical_technique FOREIGN KEY (analytical_technique_id) REFERENCES domains.waardebepalingstechniek(wbpt_id);


--
-- Name: fk_obp_certification; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY observation_process
    ADD CONSTRAINT fk_obp_certification FOREIGN KEY (certification_id) REFERENCES domains.certificeringscode(ctf_id);


--
-- Name: fk_obp_certification; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY observation_process_copy_dietmar
    ADD CONSTRAINT fk_obp_certification FOREIGN KEY (certification_id) REFERENCES domains.certificeringscode(ctf_id);


--
-- Name: fk_obp_sample_destruction_method; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY observation_process
    ADD CONSTRAINT fk_obp_sample_destruction_method FOREIGN KEY (sample_destruction_method_id) REFERENCES domains.monsterbewerkingsmethode(mbm_id);


--
-- Name: fk_obp_sample_destruction_method; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY observation_process_copy_dietmar
    ADD CONSTRAINT fk_obp_sample_destruction_method FOREIGN KEY (sample_destruction_method_id) REFERENCES domains.monsterbewerkingsmethode(mbm_id);


--
-- Name: fk_obp_sample_pre_treatment_method; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY observation_process
    ADD CONSTRAINT fk_obp_sample_pre_treatment_method FOREIGN KEY (sample_pre_treatment_method_id) REFERENCES domains.monstervoorbehandeling(mvb_id);


--
-- Name: fk_obp_sample_pre_treatment_method; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY observation_process_copy_dietmar
    ADD CONSTRAINT fk_obp_sample_pre_treatment_method FOREIGN KEY (sample_pre_treatment_method_id) REFERENCES domains.monstervoorbehandeling(mvb_id);


--
-- Name: fk_obp_sensing_location_type; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY observation_process
    ADD CONSTRAINT fk_obp_sensing_location_type FOREIGN KEY (sensing_location_type_id) REFERENCES domains.locatietype_waardebepaling(ltwb_id);


--
-- Name: fk_obp_sensing_location_type; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY observation_process_copy_dietmar
    ADD CONSTRAINT fk_obp_sensing_location_type FOREIGN KEY (sensing_location_type_id) REFERENCES domains.locatietype_waardebepaling(ltwb_id);


--
-- Name: fk_obs; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY observation_parameter
    ADD CONSTRAINT fk_obs FOREIGN KEY (obs_id) REFERENCES observation(obs_id);


--
-- Name: fk_obs_num_val_uom; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY observation
    ADD CONSTRAINT fk_obs_num_val_uom FOREIGN KEY (numeric_value_uom_id) REFERENCES eenheid_type(eenh_id);


--
-- Name: fk_obs_source; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY observation_context
    ADD CONSTRAINT fk_obs_source FOREIGN KEY (obs_id_source) REFERENCES observation(obs_id);


--
-- Name: fk_obs_target; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY observation_context
    ADD CONSTRAINT fk_obs_target FOREIGN KEY (obs_id_target) REFERENCES observation(obs_id);


--
-- Name: fk_observation_bepaling_grens_type; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY observation
    ADD CONSTRAINT fk_observation_bepaling_grens_type FOREIGN KEY (limit_symbol_id) REFERENCES bepaling_grens_type(bpg_id);


--
-- Name: fk_observation_classification_type; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY observation
    ADD CONSTRAINT fk_observation_classification_type FOREIGN KEY (classified_result_id) REFERENCES classification_type(cls_id);


--
-- Name: fk_observation_context_role_type; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY observation_context
    ADD CONSTRAINT fk_observation_context_role_type FOREIGN KEY (role_id) REFERENCES obs_ctx_role_type(ocr_id);


--
-- Name: fk_observation_kwaliteitsoordeel_type; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY observation
    ADD CONSTRAINT fk_observation_kwaliteitsoordeel_type FOREIGN KEY (quality_indicator_id) REFERENCES kwaliteitsoordeel_type(kwod_id);


--
-- Name: fk_observation_monitoring_object; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY observation
    ADD CONSTRAINT fk_observation_monitoring_object FOREIGN KEY (mno_id) REFERENCES monitoring_object(mno_id);


--
-- Name: fk_observation_observation; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY observation
    ADD CONSTRAINT fk_observation_observation FOREIGN KEY (obs_parm_parent_id) REFERENCES observation(obs_id);


--
-- Name: fk_observation_proces_namespace; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY observation_process
    ADD CONSTRAINT fk_observation_proces_namespace FOREIGN KEY (nen3610_id_namespace_id) REFERENCES namespace_type(ns_id);


--
-- Name: fk_observation_proces_namespace; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY observation_process_copy_dietmar
    ADD CONSTRAINT fk_observation_proces_namespace FOREIGN KEY (nen3610_id_namespace_id) REFERENCES namespace_type(ns_id);


--
-- Name: fk_observation_process; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY observation
    ADD CONSTRAINT fk_observation_process FOREIGN KEY (result_nature_id) REFERENCES observation_process(obp_id);


--
-- Name: fk_observation_process_waarde_bepalings_methode_type; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY observation_process
    ADD CONSTRAINT fk_observation_process_waarde_bepalings_methode_type FOREIGN KEY (wbpm_id) REFERENCES waarde_bepalings_methode_type(wbpm_id);


--
-- Name: fk_observation_process_waarde_bepalings_methode_type; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY observation_process_copy_dietmar
    ADD CONSTRAINT fk_observation_process_waarde_bepalings_methode_type FOREIGN KEY (wbpm_id) REFERENCES waarde_bepalings_methode_type(wbpm_id);


--
-- Name: fk_observation_waarde_bewerkings_methode_type; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY observation
    ADD CONSTRAINT fk_observation_waarde_bewerkings_methode_type FOREIGN KEY (value_processing_method_id) REFERENCES waarde_bewerkings_methode_type(wbm_id);


--
-- Name: fk_observed_feature_hydro_object; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY observed_feature
    ADD CONSTRAINT fk_observed_feature_hydro_object FOREIGN KEY (hdo_id) REFERENCES hydro_object(hdo_id);


--
-- Name: fk_observed_feature_observation; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY observed_feature
    ADD CONSTRAINT fk_observed_feature_observation FOREIGN KEY (obs_id) REFERENCES observation(obs_id);


--
-- Name: fk_observed_property_type; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY sw_ecological_status
    ADD CONSTRAINT fk_observed_property_type FOREIGN KEY (opt_id) REFERENCES observed_property_type(opt_id);


--
-- Name: fk_observed_property_type_classification_group_type; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY observed_property_type
    ADD CONSTRAINT fk_observed_property_type_classification_group_type FOREIGN KEY (classification_group_id) REFERENCES classification_group_type(clsg_id);


--
-- Name: fk_observed_property_type_grootheid_type; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY observed_property_type
    ADD CONSTRAINT fk_observed_property_type_grootheid_type FOREIGN KEY (quantity_id) REFERENCES grootheid_type(grh_id);


--
-- Name: fk_observed_property_type_hoedanigheid_type; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY observed_property_type
    ADD CONSTRAINT fk_observed_property_type_hoedanigheid_type FOREIGN KEY (hoedanigheid_id) REFERENCES hoedanigheid_type(hdh_id);


--
-- Name: fk_observed_property_type_object_group; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY observed_property_type
    ADD CONSTRAINT fk_observed_property_type_object_group FOREIGN KEY (object_group_id) REFERENCES object_group(ojg_id);


--
-- Name: fk_observed_property_type_opt_class_result_type_type; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY observed_property_type
    ADD CONSTRAINT fk_observed_property_type_opt_class_result_type_type FOREIGN KEY (observed_property_type_class, result_type) REFERENCES opt_class_result_type_type(observed_property_type_class_type, result_type_type);


--
-- Name: fk_observed_property_type_substance_group; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY observed_property_type
    ADD CONSTRAINT fk_observed_property_type_substance_group FOREIGN KEY (substance_group_id) REFERENCES substance_group(ssg_id);


--
-- Name: fk_observed_property_type_swb_ecol_exemp_qe; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY swb_ecol_exemp_qe
    ADD CONSTRAINT fk_observed_property_type_swb_ecol_exemp_qe FOREIGN KEY (opt_id) REFERENCES observed_property_type(opt_id);


--
-- Name: fk_observed_property_type_taxa_group; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY observed_property_type
    ADD CONSTRAINT fk_observed_property_type_taxa_group FOREIGN KEY (taxa_group_id) REFERENCES taxa_group(txg_id);


--
-- Name: fk_observed_property_type_typering_type; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY observed_property_type
    ADD CONSTRAINT fk_observed_property_type_typering_type FOREIGN KEY (indicator_id) REFERENCES typering_type(typ_id);


--
-- Name: fk_observing_capability_process_type; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY observing_capability
    ADD CONSTRAINT fk_observing_capability_process_type FOREIGN KEY (process_type_id) REFERENCES process_type(prc_id);


--
-- Name: fk_observing_capability_wkr_version; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY observing_capability
    ADD CONSTRAINT fk_observing_capability_wkr_version FOREIGN KEY (wkrv_id) REFERENCES wkr_version(wkrv_id);


--
-- Name: fk_ocbs_obs; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY observing_capability_observation
    ADD CONSTRAINT fk_ocbs_obs FOREIGN KEY (obs_id) REFERENCES observation(obs_id);


--
-- Name: fk_ocbs_osc; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY observing_capability_observation
    ADD CONSTRAINT fk_ocbs_osc FOREIGN KEY (osc_id) REFERENCES observing_capability(osc_id);


--
-- Name: fk_ocr_type_object_state; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY object_state_column_required
    ADD CONSTRAINT fk_ocr_type_object_state FOREIGN KEY (ost_id) REFERENCES object_state_type(ost_id);


--
-- Name: fk_ocrp_ore; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY observing_capability_responsible_party
    ADD CONSTRAINT fk_ocrp_ore FOREIGN KEY (ore_id) REFERENCES organisatorische_eenheid(ore_id);


--
-- Name: fk_ocrp_osc; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY observing_capability_responsible_party
    ADD CONSTRAINT fk_ocrp_osc FOREIGN KEY (osc_id) REFERENCES observing_capability(osc_id);


--
-- Name: fk_ocs_mno; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY observing_capability_sample
    ADD CONSTRAINT fk_ocs_mno FOREIGN KEY (smpl_id) REFERENCES sample(smpl_id);


--
-- Name: fk_ocs_osc; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY observing_capability_sample
    ADD CONSTRAINT fk_ocs_osc FOREIGN KEY (osc_id) REFERENCES observing_capability(osc_id);


--
-- Name: fk_opm_meetapparaat; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY obs_process_meetapparaat
    ADD CONSTRAINT fk_opm_meetapparaat FOREIGN KEY (mar_id) REFERENCES domains.meetapparaat(mar_id);


--
-- Name: fk_opm_observation_process; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY obs_process_meetapparaat
    ADD CONSTRAINT fk_opm_observation_process FOREIGN KEY (obp_id) REFERENCES observation_process(obp_id);


--
-- Name: fk_opt; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY observation
    ADD CONSTRAINT fk_opt FOREIGN KEY (observed_property_type) REFERENCES observed_property_type(opt_id);


--
-- Name: fk_opt_id; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY gw_chemical_status
    ADD CONSTRAINT fk_opt_id FOREIGN KEY (opt_id) REFERENCES observed_property_type(opt_id);


--
-- Name: fk_opt_id; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY gw_quantity_status
    ADD CONSTRAINT fk_opt_id FOREIGN KEY (opt_id) REFERENCES observed_property_type(opt_id);


--
-- Name: fk_opt_id; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY gw_swb_status
    ADD CONSTRAINT fk_opt_id FOREIGN KEY (opt_id) REFERENCES observed_property_type(opt_id);


--
-- Name: fk_opt_qe; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY wfd_qe_swtype
    ADD CONSTRAINT fk_opt_qe FOREIGN KEY (opt_id) REFERENCES observed_property_type(opt_id);


--
-- Name: fk_opt_qe; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY wfd_qe_gwtype
    ADD CONSTRAINT fk_opt_qe FOREIGN KEY (opt_id) REFERENCES observed_property_type(opt_id);


--
-- Name: fk_opt_ref; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY wfd_qe_swtype
    ADD CONSTRAINT fk_opt_ref FOREIGN KEY (part_of_opt_id) REFERENCES observed_property_type(opt_id);


--
-- Name: fk_opt_ref_eu; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY wfd_qe_gwtype
    ADD CONSTRAINT fk_opt_ref_eu FOREIGN KEY (opt_id) REFERENCES observed_property_type(opt_id);


--
-- Name: fk_opt_ref_nl; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY wfd_qe_gwtype
    ADD CONSTRAINT fk_opt_ref_nl FOREIGN KEY (opt_id) REFERENCES observed_property_type(opt_id);


--
-- Name: fk_ore_id_competentauthority_namespacetype; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY competentauthority_namespacetype
    ADD CONSTRAINT fk_ore_id_competentauthority_namespacetype FOREIGN KEY (ore_id) REFERENCES competent_authority(ore_id);


--
-- Name: fk_ore_organisation_category_type; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY organisatorische_eenheid
    ADD CONSTRAINT fk_ore_organisation_category_type FOREIGN KEY (organisation_category_id) REFERENCES organisation_category_type(ocat_id);


--
-- Name: fk_org_wkupusergroup; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY organisatorische_eenheid_wkpusergroup
    ADD CONSTRAINT fk_org_wkupusergroup FOREIGN KEY (ore_id) REFERENCES organisatorische_eenheid(ore_id);


--
-- Name: fk_organisatorische_eenheid; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY observation_process
    ADD CONSTRAINT fk_organisatorische_eenheid FOREIGN KEY (ore_id) REFERENCES organisatorische_eenheid(ore_id);


--
-- Name: fk_organisatorische_eenheid; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY observation_process_copy_dietmar
    ADD CONSTRAINT fk_organisatorische_eenheid FOREIGN KEY (ore_id) REFERENCES organisatorische_eenheid(ore_id);


--
-- Name: fk_pltr_yearly_status; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY pollutant_trend
    ADD CONSTRAINT fk_pltr_yearly_status FOREIGN KEY (gwys_id) REFERENCES gwb_yearly_status(gys_id);


--
-- Name: fk_pmfp_eumg; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY projection
    ADD CONSTRAINT fk_pmfp_eumg FOREIGN KEY (monitoring_goal_id) REFERENCES eu_monitoring_goal_type(eumg_id);


--
-- Name: fk_pmfp_pmf; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY projection
    ADD CONSTRAINT fk_pmfp_pmf FOREIGN KEY (pmf_id) REFERENCES planned_feature_monitoring(pmf_id);


--
-- Name: fk_pobb_monitored_measure; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY pom_other_basic_measure113b
    ADD CONSTRAINT fk_pobb_monitored_measure FOREIGN KEY (pobb_id) REFERENCES monitored_measure(mtm_id);


--
-- Name: fk_pobb_other_basic_measure113b_type; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY pom_other_basic_measure113b
    ADD CONSTRAINT fk_pobb_other_basic_measure113b_type FOREIGN KEY (obmb_id) REFERENCES other_basic_measure113b_type(obmb_id);


--
-- Name: fk_pobb_river_basin_management_plan; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY pom_other_basic_measure113b
    ADD CONSTRAINT fk_pobb_river_basin_management_plan FOREIGN KEY (rbmp_id) REFERENCES river_basin_management_plan(rbmp_id);


--
-- Name: fk_pom_base_measure113a_basic_measure113a_type; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY pom_base_measure113a
    ADD CONSTRAINT fk_pom_base_measure113a_basic_measure113a_type FOREIGN KEY (bma_id) REFERENCES basic_measure113a_type(bma_id);


--
-- Name: fk_pom_base_measure113a_river_basin_management_plan; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY pom_base_measure113a
    ADD CONSTRAINT fk_pom_base_measure113a_river_basin_management_plan FOREIGN KEY (rbmp_id) REFERENCES river_basin_management_plan(rbmp_id);


--
-- Name: fk_pom_base_measure113a_yes_no_not_applicable_type; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY pom_base_measure113a
    ADD CONSTRAINT fk_pom_base_measure113a_yes_no_not_applicable_type FOREIGN KEY (implemented_id) REFERENCES yes_no_not_applicable_type(ynna_id);


--
-- Name: fk_pos_acc_hor_uom; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY monitoring_feature
    ADD CONSTRAINT fk_pos_acc_hor_uom FOREIGN KEY (pos_accuracy_horizontal_uom_id) REFERENCES eenheid_type(eenh_id);


--
-- Name: fk_pos_acc_vert_uom; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY monitoring_feature
    ADD CONSTRAINT fk_pos_acc_vert_uom FOREIGN KEY (pos_accuracy_vertical_uom_id) REFERENCES eenheid_type(eenh_id);


--
-- Name: fk_qem; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY planned_feature_monitoring
    ADD CONSTRAINT fk_qem FOREIGN KEY (qem_id) REFERENCES quality_element(qem_id);


--
-- Name: fk_qem_qeo; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY quality_element_observation
    ADD CONSTRAINT fk_qem_qeo FOREIGN KEY (qem_id) REFERENCES quality_element(qem_id);


--
-- Name: fk_qeo_obs; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY quality_element_observation
    ADD CONSTRAINT fk_qeo_obs FOREIGN KEY (obs_id) REFERENCES observation(obs_id);


--
-- Name: fk_qes_mno; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY quality_element_sample
    ADD CONSTRAINT fk_qes_mno FOREIGN KEY (smpl_id) REFERENCES sample(smpl_id);


--
-- Name: fk_qes_osc; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY quality_element_sample
    ADD CONSTRAINT fk_qes_osc FOREIGN KEY (qem_id) REFERENCES quality_element(qem_id);


--
-- Name: fk_quality_element_bemonsteringsmethode; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY quality_element
    ADD CONSTRAINT fk_quality_element_bemonsteringsmethode FOREIGN KEY (sampling_method_id) REFERENCES domains.bemonsteringsmethode(bmm_id);


--
-- Name: fk_quality_element_cycle_eenheid; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY quality_element
    ADD CONSTRAINT fk_quality_element_cycle_eenheid FOREIGN KEY (cycle_uom_id) REFERENCES eenheid_type(eenh_id);


--
-- Name: fk_quality_element_observed_property_type; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY quality_element
    ADD CONSTRAINT fk_quality_element_observed_property_type FOREIGN KEY (opt_id) REFERENCES observed_property_type(opt_id);


--
-- Name: fk_quality_element_observing_capability; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY quality_element
    ADD CONSTRAINT fk_quality_element_observing_capability FOREIGN KEY (osc_id) REFERENCES observing_capability(osc_id);


--
-- Name: fk_quality_element_opt_eenheid; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY quality_element
    ADD CONSTRAINT fk_quality_element_opt_eenheid FOREIGN KEY (opt_uom_id) REFERENCES eenheid_type(eenh_id);


--
-- Name: fk_quality_element_parameter_use_type; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY quality_element
    ADD CONSTRAINT fk_quality_element_parameter_use_type FOREIGN KEY (parameter_use_id) REFERENCES parameter_use_type(prus_id);


--
-- Name: fk_quality_element_veldapparaat; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY quality_element
    ADD CONSTRAINT fk_quality_element_veldapparaat FOREIGN KEY (sampling_device_id) REFERENCES domains.veldapparaat(var_id);


--
-- Name: fk_quality_element_waarde_bewerkings_methode; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY quality_element
    ADD CONSTRAINT fk_quality_element_waarde_bewerkings_methode FOREIGN KEY (wbm_id) REFERENCES waarde_bewerkings_methode_type(wbm_id);


--
-- Name: fk_rbd_area_uom; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY river_basin_disrict
    ADD CONSTRAINT fk_rbd_area_uom FOREIGN KEY (area_uom_id) REFERENCES eenheid_type(eenh_id);


--
-- Name: fk_rbd_rbd; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY river_basin_disrict
    ADD CONSTRAINT fk_rbd_rbd FOREIGN KEY (part_of_district) REFERENCES river_basin_disrict(rbd_id);


--
-- Name: fk_rbmp_rbd; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY river_basin_management_plan
    ADD CONSTRAINT fk_rbmp_rbd FOREIGN KEY (rbd_id) REFERENCES river_basin_disrict(rbd_id);


--
-- Name: fk_rel_role_type; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY related_monitoring_object
    ADD CONSTRAINT fk_rel_role_type FOREIGN KEY (rrt_id) REFERENCES rel_role_type(rrt_id);


--
-- Name: fk_report_version_reprting_period; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY report_version
    ADD CONSTRAINT fk_report_version_reprting_period FOREIGN KEY (rpp_id) REFERENCES reporting_period(rpp_id);


--
-- Name: fk_report_version_wkr_version; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY report_version
    ADD CONSTRAINT fk_report_version_wkr_version FOREIGN KEY (wkrv_id) REFERENCES wkr_version(wkrv_id);


--
-- Name: fk_rewab_id; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY sw_abstraction_point
    ADD CONSTRAINT fk_rewab_id FOREIGN KEY (rewab_id) REFERENCES rewab_type(rwb_id);


--
-- Name: fk_rgs_relation_type; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY relation_gwb_swb
    ADD CONSTRAINT fk_rgs_relation_type FOREIGN KEY (relation_type_id) REFERENCES relation_type(rlt_id);


--
-- Name: fk_rgs_wfd_ground_water_body; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY relation_gwb_swb
    ADD CONSTRAINT fk_rgs_wfd_ground_water_body FOREIGN KEY (gwb_id) REFERENCES ground_water_body(gwb_id);


--
-- Name: fk_rgs_wfd_surface_water_body; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY relation_gwb_swb
    ADD CONSTRAINT fk_rgs_wfd_surface_water_body FOREIGN KEY (swb_id) REFERENCES surface_water_body(swb_id);


--
-- Name: fk_river_basin_management_plan_wkr_version; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY river_basin_management_plan
    ADD CONSTRAINT fk_river_basin_management_plan_wkr_version FOREIGN KEY (wkrv_id) REFERENCES wkr_version(wkrv_id);


--
-- Name: fk_rpp_legislation_reference; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY reporting_period
    ADD CONSTRAINT fk_rpp_legislation_reference FOREIGN KEY (leg_ref_id) REFERENCES legislation_reference_type(lgr_id);


--
-- Name: fk_rpv_object_state_type; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY report_version
    ADD CONSTRAINT fk_rpv_object_state_type FOREIGN KEY (ost_id) REFERENCES object_state_type(ost_id);


--
-- Name: fk_rrt_id; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY related_hydro_object
    ADD CONSTRAINT fk_rrt_id FOREIGN KEY (rrt_id) REFERENCES rel_role_type(rrt_id);


--
-- Name: fk_rsf_rel_samp_feat_role_type; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY related_sampling_feature
    ADD CONSTRAINT fk_rsf_rel_samp_feat_role_type FOREIGN KEY (role_id) REFERENCES rel_samp_feat_role_type(rsfr_id);


--
-- Name: fk_sample_biota_crit; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY sample
    ADD CONSTRAINT fk_sample_biota_crit FOREIGN KEY (biota_criterium_id) REFERENCES hoedanigheid_type(hdh_id);


--
-- Name: fk_sample_compartiment_type; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY sample
    ADD CONSTRAINT fk_sample_compartiment_type FOREIGN KEY (material_class_id) REFERENCES compartiment_type(cptm_id);


--
-- Name: fk_sample_fraction_criterium; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY sample
    ADD CONSTRAINT fk_sample_fraction_criterium FOREIGN KEY (fraction_criterium_id) REFERENCES hoedanigheid_type(hdh_id);


--
-- Name: fk_sample_orgaan; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY sample
    ADD CONSTRAINT fk_sample_orgaan FOREIGN KEY (organ_id) REFERENCES domains.orgaan(org_id);


--
-- Name: fk_sample_sampling_proces; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY sample
    ADD CONSTRAINT fk_sample_sampling_proces FOREIGN KEY (smp_id) REFERENCES sampling_proces(smp_id);


--
-- Name: fk_sample_size_uom; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY sample
    ADD CONSTRAINT fk_sample_size_uom FOREIGN KEY (size_uom_id) REFERENCES eenheid_type(eenh_id);


--
-- Name: fk_sample_taxon_type; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY sample
    ADD CONSTRAINT fk_sample_taxon_type FOREIGN KEY (txn_id) REFERENCES taxon_type(txn_id);


--
-- Name: fk_sample_upper_depth_uom; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY sample
    ADD CONSTRAINT fk_sample_upper_depth_uom FOREIGN KEY (upper_depth_uom_id) REFERENCES eenheid_type(eenh_id);


--
-- Name: fk_sampled_feature_monitoring_feature; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY sampled_feature
    ADD CONSTRAINT fk_sampled_feature_monitoring_feature FOREIGN KEY (mnf_id) REFERENCES monitoring_feature(mnf_id);


--
-- Name: fk_sampling_proces_bemonsteringsmethode; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY sampling_proces
    ADD CONSTRAINT fk_sampling_proces_bemonsteringsmethode FOREIGN KEY (sampling_method_id) REFERENCES domains.bemonsteringsmethode(bmm_id);


--
-- Name: fk_sampling_proces_monsterbewerkingsmethode; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY sampling_proces
    ADD CONSTRAINT fk_sampling_proces_monsterbewerkingsmethode FOREIGN KEY (sampling_processing_method_id) REFERENCES domains.monsterbewerkingsmethode(mbm_id);


--
-- Name: fk_sampling_proces_namespace_type; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY sampling_proces
    ADD CONSTRAINT fk_sampling_proces_namespace_type FOREIGN KEY (nen3610_id_namespace_id) REFERENCES namespace_type(ns_id);


--
-- Name: fk_sampling_proces_operator; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY sampling_proces
    ADD CONSTRAINT fk_sampling_proces_operator FOREIGN KEY (process_operator_id) REFERENCES organisatorische_eenheid(ore_id);


--
-- Name: fk_sampling_proces_organisatorische_eenheid; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY sampling_proces
    ADD CONSTRAINT fk_sampling_proces_organisatorische_eenheid FOREIGN KEY (sampling_operator_id) REFERENCES organisatorische_eenheid(ore_id);


--
-- Name: fk_sampling_proces_veldapparaat; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY sampling_proces
    ADD CONSTRAINT fk_sampling_proces_veldapparaat FOREIGN KEY (var_id) REFERENCES domains.veldapparaat(var_id);


--
-- Name: fk_scep_chemische_stof_type; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY swb_chem_exemp_pollutant
    ADD CONSTRAINT fk_scep_chemische_stof_type FOREIGN KEY (chs_id) REFERENCES chemische_stof_type(chs_id);


--
-- Name: fk_scep_swb_chemical_exemption; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY swb_chem_exemp_pollutant
    ADD CONSTRAINT fk_scep_swb_chemical_exemption FOREIGN KEY (swce_id) REFERENCES swb_exemption(swce_id);


--
-- Name: fk_slt; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY gw_monitoring_station
    ADD CONSTRAINT fk_slt FOREIGN KEY (station_level_id) REFERENCES station_level_type(slt_id);


--
-- Name: fk_smeu_eenheid_type; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY sw_supp_measure_eu_type
    ADD CONSTRAINT fk_smeu_eenheid_type FOREIGN KEY (eenh_id) REFERENCES eenheid_type(eenh_id);


--
-- Name: fk_smnl_legislation_reference_type; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY supp_add_measure_type
    ADD CONSTRAINT fk_smnl_legislation_reference_type FOREIGN KEY (legislation_ref_id) REFERENCES legislation_reference_type(lgr_id);


--
-- Name: fk_smnl_namespace_type; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY supp_add_measure_type
    ADD CONSTRAINT fk_smnl_namespace_type FOREIGN KEY (namespace_id) REFERENCES namespace_type(ns_id);


--
-- Name: fk_smnl_river_basin_management_plan; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY supp_add_measure_type
    ADD CONSTRAINT fk_smnl_river_basin_management_plan FOREIGN KEY (rbmp_id) REFERENCES river_basin_management_plan(rbmp_id);


--
-- Name: fk_smpl_low_hdh; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY sample
    ADD CONSTRAINT fk_smpl_low_hdh FOREIGN KEY (lower_depth_condition_id) REFERENCES hoedanigheid_type(hdh_id);


--
-- Name: fk_smpl_upp_hdh; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY sample
    ADD CONSTRAINT fk_smpl_upp_hdh FOREIGN KEY (upper_depth_condition_id) REFERENCES hoedanigheid_type(hdh_id);


--
-- Name: fk_spg_cw_uom; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY sw_pressures_preventing_good_status
    ADD CONSTRAINT fk_spg_cw_uom FOREIGN KEY (percentage_failure_cw_uom_id) REFERENCES eenheid_type(eenh_id);


--
-- Name: fk_spg_lw_uom; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY sw_pressures_preventing_good_status
    ADD CONSTRAINT fk_spg_lw_uom FOREIGN KEY (percentage_failure_lw_uom_id) REFERENCES eenheid_type(eenh_id);


--
-- Name: fk_spg_rbmp; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY sw_pressures_preventing_good_status
    ADD CONSTRAINT fk_spg_rbmp FOREIGN KEY (rbmp_id) REFERENCES river_basin_management_plan(rbmp_id);


--
-- Name: fk_spg_rw_uom; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY sw_pressures_preventing_good_status
    ADD CONSTRAINT fk_spg_rw_uom FOREIGN KEY (percentage_failure_rw_uom_id) REFERENCES eenheid_type(eenh_id);


--
-- Name: fk_spg_swp; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY sw_pressures_preventing_good_status
    ADD CONSTRAINT fk_spg_swp FOREIGN KEY (swap_id) REFERENCES sw_aggregated_pressure_type(swap_id);


--
-- Name: fk_spg_tw_uom; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY sw_pressures_preventing_good_status
    ADD CONSTRAINT fk_spg_tw_uom FOREIGN KEY (percentage_failure_tw_uom_id) REFERENCES eenheid_type(eenh_id);


--
-- Name: fk_sprm_basic_measure113a_type; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY sw_pressure_requiring_supp_add_measures
    ADD CONSTRAINT fk_sprm_basic_measure113a_type FOREIGN KEY (bma_id) REFERENCES basic_measure113a_type(bma_id);


--
-- Name: fk_sprm_other_basic_measure113b_type; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY sw_pressure_requiring_supp_add_measures
    ADD CONSTRAINT fk_sprm_other_basic_measure113b_type FOREIGN KEY (obmb_id) REFERENCES other_basic_measure113b_type(obmb_id);


--
-- Name: fk_sprm_sw_pressure_type; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY sw_pressure_requiring_supp_add_measures
    ADD CONSTRAINT fk_sprm_sw_pressure_type FOREIGN KEY (sprs_id) REFERENCES sw_pressure_type(sprs_id);


--
-- Name: fk_sprm_sw_pressures_preventing_good_status; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY sw_pressure_requiring_supp_add_measures
    ADD CONSTRAINT fk_sprm_sw_pressures_preventing_good_status FOREIGN KEY (spg_id) REFERENCES sw_pressures_preventing_good_status(spg_id);


--
-- Name: fk_sprs_pressure_category_type; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY sw_pressure_type
    ADD CONSTRAINT fk_sprs_pressure_category_type FOREIGN KEY (pressure_category_id) REFERENCES pressure_category_type(pcat_id);


--
-- Name: fk_sptcat_sw_category_type; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY sw_pressure_type_type_category
    ADD CONSTRAINT fk_sptcat_sw_category_type FOREIGN KEY (swc_id) REFERENCES sw_category_type(swc_id);


--
-- Name: fk_sptcat_sw_pressure_type; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY sw_pressure_type_type_category
    ADD CONSTRAINT fk_sptcat_sw_pressure_type FOREIGN KEY (sprs_id) REFERENCES sw_pressure_type(sprs_id);


--
-- Name: fk_srsm_sprm; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY sw_required_supp_measure
    ADD CONSTRAINT fk_srsm_sprm FOREIGN KEY (sprm_id) REFERENCES sw_pressure_requiring_supp_add_measures(sprm_id);


--
-- Name: fk_srsm_supp_add_measure_nl_type; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY sw_required_supp_measure
    ADD CONSTRAINT fk_srsm_supp_add_measure_nl_type FOREIGN KEY (smnl_id) REFERENCES supp_add_measure_type(smnl_id);


--
-- Name: fk_sst; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY monitoring_station
    ADD CONSTRAINT fk_sst FOREIGN KEY (subsite_type_id) REFERENCES subsite_type(sst_id);


--
-- Name: fk_stcc_eumg_id; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY sw_testing_conclusion
    ADD CONSTRAINT fk_stcc_eumg_id FOREIGN KEY (eumg_id) REFERENCES eu_monitoring_goal_type(eumg_id);


--
-- Name: fk_stcc_observation; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY sw_testing_conclusion
    ADD CONSTRAINT fk_stcc_observation FOREIGN KEY (stcc_id) REFERENCES observation(obs_id);


--
-- Name: fk_stcc_swb_yearly_status; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY sw_testing_conclusion
    ADD CONSTRAINT fk_stcc_swb_yearly_status FOREIGN KEY (sys_id) REFERENCES swb_yearly_status(sys_id);


--
-- Name: fk_stt; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY gw_monitoring_station
    ADD CONSTRAINT fk_stt FOREIGN KEY (station_type_id) REFERENCES station_type_type(stt_id);


--
-- Name: fk_styp_sw_category_type; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY sw_typology_type
    ADD CONSTRAINT fk_styp_sw_category_type FOREIGN KEY (swc_id) REFERENCES sw_category_type(swc_id);


--
-- Name: fk_supp_add_measure_type_monitored_measure; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY supp_add_measure_type
    ADD CONSTRAINT fk_supp_add_measure_type_monitored_measure FOREIGN KEY (smnl_id) REFERENCES monitored_measure(mtm_id);


--
-- Name: fk_supp_add_measure_type_sw_supp_measure_eu_type; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY supp_add_measure_type
    ADD CONSTRAINT fk_supp_add_measure_type_sw_supp_measure_eu_type FOREIGN KEY (smeu_id) REFERENCES sw_supp_measure_eu_type(smeu_id);


--
-- Name: fk_surface_water_body_reason_change_type; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY surface_water_body
    ADD CONSTRAINT fk_surface_water_body_reason_change_type FOREIGN KEY (rct_id) REFERENCES reason_change_type(rct_id);


--
-- Name: fk_surface_water_body_sw_target_typology_type; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY surface_water_body
    ADD CONSTRAINT fk_surface_water_body_sw_target_typology_type FOREIGN KEY (sw_target_typology_id) REFERENCES sw_typology_type(styp_id);


--
-- Name: fk_surface_water_body_sw_typology_type; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY surface_water_body
    ADD CONSTRAINT fk_surface_water_body_sw_typology_type FOREIGN KEY (sw_typology_id) REFERENCES sw_typology_type(styp_id);


--
-- Name: fk_sw_chemical_status; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY sw_chemical_substance_status
    ADD CONSTRAINT fk_sw_chemical_status FOREIGN KEY (swcs_id) REFERENCES classification_type(cls_id);


--
-- Name: fk_sw_chemical_substance_status_swb_yearly_status; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY sw_chemical_substance_status
    ADD CONSTRAINT fk_sw_chemical_substance_status_swb_yearly_status FOREIGN KEY (sys_id) REFERENCES swb_yearly_status(sys_id);


--
-- Name: fk_sw_ecological_status_swb_yearly_status; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY sw_ecological_status
    ADD CONSTRAINT fk_sw_ecological_status_swb_yearly_status FOREIGN KEY (sys_id) REFERENCES swb_yearly_status(sys_id);


--
-- Name: fk_sw_intercalibration_type; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY sw_typology_type
    ADD CONSTRAINT fk_sw_intercalibration_type FOREIGN KEY (icalt_id) REFERENCES eu_intercalibration_type(icalt);


--
-- Name: fk_sw_pressure_type_driver; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY sw_pressure_type_driver
    ADD CONSTRAINT fk_sw_pressure_type_driver FOREIGN KEY (driver_id) REFERENCES domains.drivers(driver_id);


--
-- Name: fk_sw_pressure_type_sprs; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY sw_pressure_type_driver
    ADD CONSTRAINT fk_sw_pressure_type_sprs FOREIGN KEY (sprs_id) REFERENCES sw_pressure_type(sprs_id);


--
-- Name: fk_sw_test_value_norm_value; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY sw_test_value
    ADD CONSTRAINT fk_sw_test_value_norm_value FOREIGN KEY (nrmv_id) REFERENCES norm_value(nrmv_id);


--
-- Name: fk_swap_id; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY sw_abstraction_point
    ADD CONSTRAINT fk_swap_id FOREIGN KEY (sasp_id) REFERENCES abstraction_point(asp_id);


--
-- Name: fk_swat_id; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY sw_abstraction_point
    ADD CONSTRAINT fk_swat_id FOREIGN KEY (swat_id) REFERENCES sw_abstraction_type(swat_id);


--
-- Name: fk_swb_area_eenheid_type; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY surface_water_body
    ADD CONSTRAINT fk_swb_area_eenheid_type FOREIGN KEY (area_uom_id) REFERENCES eenheid_type(eenh_id);


--
-- Name: fk_swb_excemption; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY swb_excemption_mechanism_44
    ADD CONSTRAINT fk_swb_excemption FOREIGN KEY (swce_id) REFERENCES swb_exemption(swce_id);


--
-- Name: fk_swb_exemption_swb_ecol_exemp_qe; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY swb_ecol_exemp_qe
    ADD CONSTRAINT fk_swb_exemption_swb_ecol_exemp_qe FOREIGN KEY (swce_id) REFERENCES swb_exemption(swce_id);


--
-- Name: fk_swb_id; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY gw_swb_status
    ADD CONSTRAINT fk_swb_id FOREIGN KEY (swb_id) REFERENCES surface_water_body(swb_id);


--
-- Name: fk_swb_length_eenheid_type; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY surface_water_body
    ADD CONSTRAINT fk_swb_length_eenheid_type FOREIGN KEY (length_uom_id) REFERENCES eenheid_type(eenh_id);


--
-- Name: fk_swb_physical_alteration_pat; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY swb_physical_alteration
    ADD CONSTRAINT fk_swb_physical_alteration_pat FOREIGN KEY (pat_id) REFERENCES physical_alteration_type(pat_id);


--
-- Name: fk_swb_physical_alteration_swb; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY swb_physical_alteration
    ADD CONSTRAINT fk_swb_physical_alteration_swb FOREIGN KEY (swb_id) REFERENCES surface_water_body(swb_id);


--
-- Name: fk_swb_pressure_impact; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY swb_pressure_impact
    ADD CONSTRAINT fk_swb_pressure_impact FOREIGN KEY (impact_id) REFERENCES domains.impacts(impact_id);


--
-- Name: fk_swb_pressure_swbp; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY swb_pressure_impact
    ADD CONSTRAINT fk_swb_pressure_swbp FOREIGN KEY (swbp_id) REFERENCES swb_pressure(swbp_id);


--
-- Name: fk_swb_prognosis_cls; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY wb_prognosis
    ADD CONSTRAINT fk_swb_prognosis_cls FOREIGN KEY (cls_id) REFERENCES classification_type(cls_id);


--
-- Name: fk_swb_prognosis_opt; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY wb_prognosis
    ADD CONSTRAINT fk_swb_prognosis_opt FOREIGN KEY (opt_id) REFERENCES observed_property_type(opt_id);


--
-- Name: fk_swb_prognosis_wb; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY wb_prognosis
    ADD CONSTRAINT fk_swb_prognosis_wb FOREIGN KEY (swb_id) REFERENCES water_body(wbd_id);


--
-- Name: fk_swb_yearly_status; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY chemical_exceedance
    ADD CONSTRAINT fk_swb_yearly_status FOREIGN KEY (sys_id) REFERENCES swb_yearly_status(sys_id);


--
-- Name: fk_swb_yearly_status_surface_water_body; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY swb_yearly_status
    ADD CONSTRAINT fk_swb_yearly_status_surface_water_body FOREIGN KEY (swb_id) REFERENCES surface_water_body(swb_id);


--
-- Name: fk_swbtype_qe; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY wfd_qe_swtype
    ADD CONSTRAINT fk_swbtype_qe FOREIGN KEY (swt_id) REFERENCES sw_typology_type(styp_id);


--
-- Name: fk_swce_objectives_exemption_type; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY swb_exemption
    ADD CONSTRAINT fk_swce_objectives_exemption_type FOREIGN KEY (obex_id) REFERENCES objectives_exemption_type(obex_id);


--
-- Name: fk_swce_surface_water_body; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY swb_exemption
    ADD CONSTRAINT fk_swce_surface_water_body FOREIGN KEY (swb_id) REFERENCES surface_water_body(swb_id);


--
-- Name: fk_swcs_confidence_level_type; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY sw_chemical_substance_status
    ADD CONSTRAINT fk_swcs_confidence_level_type FOREIGN KEY (clt_id) REFERENCES domains.confidence_level_type(clt_id);


--
-- Name: fk_swee_function; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY swb_measures_43a
    ADD CONSTRAINT fk_swee_function FOREIGN KEY (fu43_id) REFERENCES eu_function_43a_type(fu43_id);


--
-- Name: fk_swee_surface_water_body; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY swb_measures_43a
    ADD CONSTRAINT fk_swee_surface_water_body FOREIGN KEY (swb_id) REFERENCES surface_water_body(swb_id);


--
-- Name: fk_swes_confidence_level_type; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY sw_ecological_status
    ADD CONSTRAINT fk_swes_confidence_level_type FOREIGN KEY (clt_id) REFERENCES domains.confidence_level_type(clt_id);


--
-- Name: fk_swpr_ground_water_body; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY swb_pressure
    ADD CONSTRAINT fk_swpr_ground_water_body FOREIGN KEY (swb_id) REFERENCES surface_water_body(swb_id);


--
-- Name: fk_swpr_sw_pressure_type; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY swb_pressure
    ADD CONSTRAINT fk_swpr_sw_pressure_type FOREIGN KEY (sprs_id) REFERENCES sw_pressure_type(sprs_id);


--
-- Name: fk_taxa_group; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY taxa_group_element
    ADD CONSTRAINT fk_taxa_group FOREIGN KEY (txg_id) REFERENCES taxa_group(txg_id);


--
-- Name: fk_taxon_type; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY taxa_group_element
    ADD CONSTRAINT fk_taxon_type FOREIGN KEY (txn_id) REFERENCES taxon_type(txn_id);


--
-- Name: fk_thema_actie_organisatorische_eenheid_voortgang_actie; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY thema_actie_organisatorische_eenheid_voortgang
    ADD CONSTRAINT fk_thema_actie_organisatorische_eenheid_voortgang_actie FOREIGN KEY (ta_id) REFERENCES thema_acties(ta_id) ON UPDATE CASCADE ON DELETE CASCADE;


--
-- Name: fk_thema_actie_organisatorische_eenheid_voortgang_organisatoris; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY thema_actie_organisatorische_eenheid_voortgang
    ADD CONSTRAINT fk_thema_actie_organisatorische_eenheid_voortgang_organisatoris FOREIGN KEY (ore_id) REFERENCES organisatorische_eenheid(ore_id) ON UPDATE CASCADE ON DELETE CASCADE;


--
-- Name: fk_thema_acties_thema; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY thema_acties
    ADD CONSTRAINT fk_thema_acties_thema FOREIGN KEY (t_id) REFERENCES themas(t_id);


--
-- Name: fk_thema_overzicht_groep_organisatorische_eenheden_organisatori; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY thema_overzicht_groep_organisatorische_eenheden
    ADD CONSTRAINT fk_thema_overzicht_groep_organisatorische_eenheden_organisatori FOREIGN KEY (ore_id) REFERENCES organisatorische_eenheid(ore_id) ON UPDATE CASCADE ON DELETE CASCADE;


--
-- Name: fk_thema_overzicht_groep_organisatorische_eenheden_thema_overzi; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY thema_overzicht_groep_organisatorische_eenheden
    ADD CONSTRAINT fk_thema_overzicht_groep_organisatorische_eenheden_thema_overzi FOREIGN KEY (tog_id) REFERENCES thema_overzicht_groepen(tog_id) ON UPDATE CASCADE ON DELETE CASCADE;


--
-- Name: fk_thema_overzicht_groep_river_basin_disrict_rbd; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY thema_overzicht_groep_river_basin_disrict
    ADD CONSTRAINT fk_thema_overzicht_groep_river_basin_disrict_rbd FOREIGN KEY (rbd_id) REFERENCES river_basin_disrict(rbd_id) ON UPDATE CASCADE ON DELETE CASCADE;


--
-- Name: fk_thema_overzicht_groep_river_basin_disrict_tog; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY thema_overzicht_groep_river_basin_disrict
    ADD CONSTRAINT fk_thema_overzicht_groep_river_basin_disrict_tog FOREIGN KEY (tog_id) REFERENCES thema_overzicht_groepen(tog_id) ON UPDATE CASCADE ON DELETE CASCADE;


--
-- Name: fk_thema_overzicht_groep_wkpusers_thema_overzicht_groep; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY thema_overzicht_groep_wkpusers
    ADD CONSTRAINT fk_thema_overzicht_groep_wkpusers_thema_overzicht_groep FOREIGN KEY (tog_id) REFERENCES thema_overzicht_groepen(tog_id) ON UPDATE CASCADE ON DELETE CASCADE;


--
-- Name: fk_thema_overzicht_statussen_thema; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY thema_overzicht_statussen
    ADD CONSTRAINT fk_thema_overzicht_statussen_thema FOREIGN KEY (t_id) REFERENCES themas(t_id);


--
-- Name: fk_to_hdo; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY related_hydro_object
    ADD CONSTRAINT fk_to_hdo FOREIGN KEY (to_hdo) REFERENCES hydro_object(hdo_id);


--
-- Name: fk_to_mno; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY related_monitoring_object
    ADD CONSTRAINT fk_to_mno FOREIGN KEY (to_mno) REFERENCES monitoring_object(mno_id);


--
-- Name: fk_trendtype_cls_id; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY pollutant_trend
    ADD CONSTRAINT fk_trendtype_cls_id FOREIGN KEY (cls_id) REFERENCES classification_type(cls_id);


--
-- Name: fk_true_styp_sw_category_type; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY sw_typology_type
    ADD CONSTRAINT fk_true_styp_sw_category_type FOREIGN KEY (true_swc_id) REFERENCES sw_category_type(swc_id);


--
-- Name: fk_upperbound_eenheid; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY norm_value
    ADD CONSTRAINT fk_upperbound_eenheid FOREIGN KEY (upperbound_uom_id) REFERENCES eenheid_type(eenh_id);


--
-- Name: fk_upperbound_limiet; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY norm_value
    ADD CONSTRAINT fk_upperbound_limiet FOREIGN KEY (upperbound_limit_symbol_id) REFERENCES bepaling_grens_type(bpg_id);


--
-- Name: fk_valid_column_uom_eenheid_type; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY valid_column_uom
    ADD CONSTRAINT fk_valid_column_uom_eenheid_type FOREIGN KEY (uom_id) REFERENCES eenheid_type(eenh_id);


--
-- Name: fk_waarde_bepalings_methode_type; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY observation_process
    ADD CONSTRAINT fk_waarde_bepalings_methode_type FOREIGN KEY (wbpm_id) REFERENCES waarde_bepalings_methode_type(wbpm_id);


--
-- Name: fk_waarde_bepalings_methode_type; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY sw_chemical_substance_status
    ADD CONSTRAINT fk_waarde_bepalings_methode_type FOREIGN KEY (wbpm_id) REFERENCES waarde_bepalings_methode_type(wbpm_id);


--
-- Name: fk_waarde_bepalings_methode_type; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY sw_ecological_status
    ADD CONSTRAINT fk_waarde_bepalings_methode_type FOREIGN KEY (wbpm_id) REFERENCES waarde_bepalings_methode_type(wbpm_id);


--
-- Name: fk_waarde_bepalings_methode_type; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY gw_chemical_status
    ADD CONSTRAINT fk_waarde_bepalings_methode_type FOREIGN KEY (wbpm_id) REFERENCES waarde_bepalings_methode_type(wbpm_id);


--
-- Name: fk_waarde_bepalings_methode_type; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY observation_process_copy_dietmar
    ADD CONSTRAINT fk_waarde_bepalings_methode_type FOREIGN KEY (wbpm_id) REFERENCES waarde_bepalings_methode_type(wbpm_id);


--
-- Name: fk_watercourse_hydro_object; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY watercourse
    ADD CONSTRAINT fk_watercourse_hydro_object FOREIGN KEY (wtc_id) REFERENCES hydro_object(hdo_id);


--
-- Name: fk_wbd_mrz; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY water_body
    ADD CONSTRAINT fk_wbd_mrz FOREIGN KEY (wbd_id) REFERENCES management_regulation_or_restriction_zone(mrz_id);


--
-- Name: fk_wbd_rbd; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY water_body
    ADD CONSTRAINT fk_wbd_rbd FOREIGN KEY (rbd_id) REFERENCES river_basin_disrict(rbd_id);


--
-- Name: fk_wbp_relation_type; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY waterbody_protected_area_intersection
    ADD CONSTRAINT fk_wbp_relation_type FOREIGN KEY (relation_type) REFERENCES relation_type(rlt_id);


--
-- Name: fk_wbp_wbd; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY waterbody_protected_area_intersection
    ADD CONSTRAINT fk_wbp_wbd FOREIGN KEY (wbd_id) REFERENCES water_body(wbd_id);


--
-- Name: fk_wbp_wpa; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY waterbody_protected_area_intersection
    ADD CONSTRAINT fk_wbp_wpa FOREIGN KEY (wpa_id) REFERENCES wfd_protected_area(wpa_id);


--
-- Name: fk_wbpm_id; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY gw_quantity_status
    ADD CONSTRAINT fk_wbpm_id FOREIGN KEY (wbpm_id) REFERENCES waarde_bepalings_methode_type(wbpm_id);


--
-- Name: fk_wbsc_observed_property; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY wb_status_change_motivation
    ADD CONSTRAINT fk_wbsc_observed_property FOREIGN KEY (opt_id) REFERENCES observed_property_type(opt_id);


--
-- Name: fk_wbsc_status_change_motivation; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY wb_status_change_motivation
    ADD CONSTRAINT fk_wbsc_status_change_motivation FOREIGN KEY (scm_id) REFERENCES domains.status_change_motivation_type(scm_id);


--
-- Name: fk_wbsc_water_body; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY wb_status_change_motivation
    ADD CONSTRAINT fk_wbsc_water_body FOREIGN KEY (wbd_id) REFERENCES water_body(wbd_id);


--
-- Name: fk_wfd_ground_water_body_wfd_water_body; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY ground_water_body
    ADD CONSTRAINT fk_wfd_ground_water_body_wfd_water_body FOREIGN KEY (gwb_id) REFERENCES water_body(wbd_id);


--
-- Name: fk_wfd_surface_water_body_wfd_water_body; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY surface_water_body
    ADD CONSTRAINT fk_wfd_surface_water_body_wfd_water_body FOREIGN KEY (swb_id) REFERENCES water_body(wbd_id);


--
-- Name: fk_wkpuser_settings; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY wkpuser_settings
    ADD CONSTRAINT fk_wkpuser_settings FOREIGN KEY (wkpuserid) REFERENCES wkpuser(wkpuserid);


--
-- Name: fk_wkpusergroupid; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY organisatorische_eenheid_wkpusergroup
    ADD CONSTRAINT fk_wkpusergroupid FOREIGN KEY (wkpusergroupid) REFERENCES wkpusergroup(wkpusergroupid);


--
-- Name: fk_wpa_mrz; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY wfd_protected_area
    ADD CONSTRAINT fk_wpa_mrz FOREIGN KEY (wpa_id) REFERENCES management_regulation_or_restriction_zone(mrz_id);


--
-- Name: fk_wpa_protected_area_type; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY wfd_protected_area
    ADD CONSTRAINT fk_wpa_protected_area_type FOREIGN KEY (protected_area_type_id) REFERENCES protected_area_type(pat_id);


--
-- Name: fk_wpa_wfd_ground_water_body; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY wfd_protected_area
    ADD CONSTRAINT fk_wpa_wfd_ground_water_body FOREIGN KEY (gwb_art7_id) REFERENCES ground_water_body(gwb_id);


--
-- Name: fk_wpa_wfd_status_code; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY wfd_protected_area
    ADD CONSTRAINT fk_wpa_wfd_status_code FOREIGN KEY (protected_area_status_id) REFERENCES wfd_status_code(wsc_id);


--
-- Name: fk_wpa_wfd_surface_water_body; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY wfd_protected_area
    ADD CONSTRAINT fk_wpa_wfd_surface_water_body FOREIGN KEY (swb_art7_id) REFERENCES surface_water_body(swb_id);


--
-- Name: fk_wtclt_watercourse; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY watercourse_local_type
    ADD CONSTRAINT fk_wtclt_watercourse FOREIGN KEY (wtc_id) REFERENCES watercourse(wtc_id) ON DELETE CASCADE;


--
-- Name: gw_status_type; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY gw_quantity_status
    ADD CONSTRAINT gw_status_type FOREIGN KEY (gwst_id) REFERENCES classification_type(cls_id);


--
-- Name: gwb_conceptual_model_ground_water_body_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY gwb_conceptual_model
    ADD CONSTRAINT gwb_conceptual_model_ground_water_body_fkey FOREIGN KEY (gwb_id) REFERENCES ground_water_body(gwb_id);


--
-- Name: importrule_importtype_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY importrule
    ADD CONSTRAINT importrule_importtype_fkey FOREIGN KEY (importtypeid) REFERENCES importtype(importtypeid) ON UPDATE CASCADE ON DELETE CASCADE;


--
-- Name: linkedimportrule_importrule_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY importrule
    ADD CONSTRAINT linkedimportrule_importrule_fkey FOREIGN KEY (linkedimportruleid) REFERENCES importtype(importtypeid) ON UPDATE CASCADE ON DELETE CASCADE;


--
-- Name: lowerbound_limiet; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY norm_value
    ADD CONSTRAINT lowerbound_limiet FOREIGN KEY (lowerbound_limit_symbol_id) REFERENCES bepaling_grens_type(bpg_id);


--
-- Name: membership_application_applicationid_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY membership
    ADD CONSTRAINT membership_application_applicationid_fkey FOREIGN KEY (applicationid) REFERENCES application(applicationid) ON UPDATE CASCADE ON DELETE CASCADE;


--
-- Name: membership_application_wkpuserid_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY membership
    ADD CONSTRAINT membership_application_wkpuserid_fkey FOREIGN KEY (wkpuserid) REFERENCES wkpuser(wkpuserid) ON UPDATE CASCADE ON DELETE CASCADE;


--
-- Name: page_group_page_pagegroup_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY page_pagegroup
    ADD CONSTRAINT page_group_page_pagegroup_fkey FOREIGN KEY (pg_id) REFERENCES page_group(pg_id);


--
-- Name: page_group_wkpuser_pagegroup_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY wkpuser_pagegroup
    ADD CONSTRAINT page_group_wkpuser_pagegroup_fkey FOREIGN KEY (pg_id) REFERENCES page_group(pg_id);


--
-- Name: page_page_pagegroup_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY page_pagegroup
    ADD CONSTRAINT page_page_pagegroup_fkey FOREIGN KEY (page_id) REFERENCES page(page_id);


--
-- Name: profile_wkpuser_wkpuserid_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY profile
    ADD CONSTRAINT profile_wkpuser_wkpuserid_fkey FOREIGN KEY (wkpuserid) REFERENCES wkpuser(wkpuserid) ON UPDATE CASCADE ON DELETE CASCADE;


--
-- Name: related_zone; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY management_regulation_or_restriction_zone
    ADD CONSTRAINT related_zone FOREIGN KEY (related_mrz_id) REFERENCES management_regulation_or_restriction_zone(mrz_id);


--
-- Name: relation_ore_wbd_organisatorische_eenheid_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY relation_ore_wbd
    ADD CONSTRAINT relation_ore_wbd_organisatorische_eenheid_fkey FOREIGN KEY (ore_id) REFERENCES organisatorische_eenheid(ore_id);


--
-- Name: relation_ore_wbd_water_body_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY relation_ore_wbd
    ADD CONSTRAINT relation_ore_wbd_water_body_fkey FOREIGN KEY (wbd_id) REFERENCES water_body(wbd_id);


--
-- Name: role_application_applicationid_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY role
    ADD CONSTRAINT role_application_applicationid_fkey FOREIGN KEY (applicationid) REFERENCES application(applicationid) ON UPDATE CASCADE ON DELETE CASCADE;


--
-- Name: sw_chemical_substance_status_opt_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY sw_chemical_substance_status
    ADD CONSTRAINT sw_chemical_substance_status_opt_id_fkey FOREIGN KEY (opt_id) REFERENCES observed_property_type(opt_id);


--
-- Name: transformation_importrule_importruleid_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY transformation
    ADD CONSTRAINT transformation_importrule_importruleid_fkey FOREIGN KEY (importruleid) REFERENCES importrule(importruleid) ON UPDATE CASCADE ON DELETE CASCADE;


--
-- Name: validation_importtype_importtypeid_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY validation_importtype
    ADD CONSTRAINT validation_importtype_importtypeid_fkey FOREIGN KEY (importtypeid) REFERENCES importtype(importtypeid) ON UPDATE CASCADE ON DELETE CASCADE;


--
-- Name: validation_importtype_validationid_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY validation_importtype
    ADD CONSTRAINT validation_importtype_validationid_fkey FOREIGN KEY (validationid) REFERENCES validation(validationid) ON UPDATE CASCADE ON DELETE CASCADE;


--
-- Name: volumestroom_type_bronnen_bronnen_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY volumestroom_type_bronnen
    ADD CONSTRAINT volumestroom_type_bronnen_bronnen_fkey FOREIGN KEY (bronnen_id) REFERENCES bronnen(bronnen_id);


--
-- Name: volumestroom_type_bronnen_volumestroom_type_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY volumestroom_type_bronnen
    ADD CONSTRAINT volumestroom_type_bronnen_volumestroom_type_fkey FOREIGN KEY (vst_id) REFERENCES volumestroom_type(vst_id);


--
-- Name: wkpuser_application_applicationid_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY wkpuser
    ADD CONSTRAINT wkpuser_application_applicationid_fkey FOREIGN KEY (applicationid) REFERENCES application(applicationid) ON UPDATE CASCADE ON DELETE CASCADE;


--
-- Name: wkpuser_importtype_importtypeid_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY wkpuser_importtype
    ADD CONSTRAINT wkpuser_importtype_importtypeid_fkey FOREIGN KEY (importtypeid) REFERENCES importtype(importtypeid) ON UPDATE CASCADE ON DELETE CASCADE;


--
-- Name: wkpuser_importtype_wkpuserid_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY wkpuser_importtype
    ADD CONSTRAINT wkpuser_importtype_wkpuserid_fkey FOREIGN KEY (wkpuserid) REFERENCES wkpuser(wkpuserid) ON UPDATE CASCADE ON DELETE CASCADE;


--
-- Name: wkpuser_role_role_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY wkpuserinrole
    ADD CONSTRAINT wkpuser_role_role_id_fkey FOREIGN KEY (roleid) REFERENCES role(roleid) ON UPDATE CASCADE ON DELETE CASCADE;


--
-- Name: wkpuser_role_wkpuser_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY wkpuserinrole
    ADD CONSTRAINT wkpuser_role_wkpuser_id_fkey FOREIGN KEY (wkpuserid) REFERENCES wkpuser(wkpuserid) ON UPDATE CASCADE ON DELETE CASCADE;


--
-- Name: wkpuser_wkpuser_pagegroup_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY wkpuser_pagegroup
    ADD CONSTRAINT wkpuser_wkpuser_pagegroup_fkey FOREIGN KEY (wkpuserid) REFERENCES wkpuser(wkpuserid);


--
-- Name: wkpusergroupid_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY wkpuser_wkpusergroup
    ADD CONSTRAINT wkpusergroupid_fkey FOREIGN KEY (wkpusergroupid) REFERENCES wkpusergroup(wkpusergroupid);


--
-- Name: wkpuserid_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY wkpuser_wkpusergroup
    ADD CONSTRAINT wkpuserid_fkey FOREIGN KEY (wkpuserid) REFERENCES wkpuser(wkpuserid);



--
-- Name: fk; Type: FK CONSTRAINT; Schema: wfd_reporting; Owner: -
--

ALTER TABLE ONLY significant_impact_enum
    ADD CONSTRAINT fk FOREIGN KEY (i_id) REFERENCES domains.impacts(impact_id);


--
-- Name: fk_nl; Type: FK CONSTRAINT; Schema: wfd_reporting; Owner: -
--

ALTER TABLE ONLY geological_formation_enum
    ADD CONSTRAINT fk_nl FOREIGN KEY (nl_id) REFERENCES public.geological_formation_type(gfm_id);


--
-- Name: fk_sw; Type: FK CONSTRAINT; Schema: wfd_reporting; Owner: -
--

ALTER TABLE ONLY significant_pressure_enum
    ADD CONSTRAINT fk_sw FOREIGN KEY (sw_p_id) REFERENCES public.sw_pressure_type(sprs_id);


--
-- Name: pk_gw; Type: FK CONSTRAINT; Schema: wfd_reporting; Owner: -
--

ALTER TABLE ONLY significant_pressure_enum
    ADD CONSTRAINT pk_gw FOREIGN KEY (gw_p_id) REFERENCES public.gw_pressure_type(gprs_id);


--
-- Name: smeu; Type: FK CONSTRAINT; Schema: wfd_reporting; Owner: -
--

ALTER TABLE ONLY ktm_enum
    ADD CONSTRAINT smeu FOREIGN KEY (smeu_id) REFERENCES public.sw_supp_measure_eu_type(smeu_id);


--domain table BiologischKenmerk 
CREATE TABLE if not exists "public".BiologischKenmerk
(
  ID BIGINT
, Code VARCHAR(30)
, Omschrijving VARCHAR(60)
, Groep VARCHAR(17)
, D_BEGIN date
, D_EIND date
, D_STATUS VARCHAR(1)
)
;CREATE INDEX if not exists idx_BiologischKenmerk_lookup ON "public".BiologischKenmerk(Code)
;
