Project

General

Profile

« Previous | Next » 

Revision 704

vegbien.sql: Ensure that aggregateoccurrence.count == 1 when the aggregateoccurrence has a plantobservation. Use a trigger to do this automatically.

View differences:

vegbien.sql
18 18
SET search_path = public, pg_catalog;
19 19

  
20 20
--
21
-- Name: aggregateoccurrence_plantobs_count_1(); Type: FUNCTION; Schema: public; Owner: -
22
--
23

  
24
CREATE FUNCTION aggregateoccurrence_plantobs_count_1() RETURNS trigger
25
    LANGUAGE plpgsql
26
    AS $$
27
BEGIN
28
    IF new.plantobservation_id IS NOT NULL THEN
29
        new.count = 1;
30
    END IF;
31
    RETURN new;
32
END;
33
$$;
34

  
35

  
36
--
21 37
-- Name: concat(text); Type: AGGREGATE; Schema: public; Owner: -
22 38
--
23 39

  
......
92 108
    plantobservation_id integer,
93 109
    stratum_id integer,
94 110
    sizeclass_id integer,
95
    coverindex_id integer
111
    coverindex_id integer,
112
    CONSTRAINT aggregateoccurrence_plantobs_count_1 CHECK (((plantobservation_id IS NULL) OR (NOT (count IS DISTINCT FROM 1))))
96 113
);
97 114

  
98 115

  
......
5957 5974

  
5958 5975

  
5959 5976
--
5977
-- Name: aggregateoccurrence_plantobs_count_1; Type: TRIGGER; Schema: public; Owner: -
5978
--
5979

  
5980
CREATE TRIGGER aggregateoccurrence_plantobs_count_1 BEFORE INSERT OR UPDATE ON aggregateoccurrence FOR EACH ROW EXECUTE PROCEDURE aggregateoccurrence_plantobs_count_1();
5981

  
5982

  
5983
--
5960 5984
-- Name: address_organization_id; Type: FK CONSTRAINT; Schema: public; Owner: -
5961 5985
--
5962 5986

  

Also available in: Unified diff