Project

General

Profile

« Previous | Next » 

Revision 6421

schemas/vegbien.sql: taxondetermination: Added AFTER trigger to set the current taxondetermination for the taxonoccurrence

View differences:

schemas/vegbien.my.sql
388 388

  
389 389

  
390 390
--
391
-- Name: taxondetermination_set_iscurrent(); Type: FUNCTION; Schema: public; Owner: -
392
--
393

  
394

  
395

  
396

  
397
--
391 398
-- Name: taxonlabel_0_matched_label_id_self_ref(); Type: FUNCTION; Schema: public; Owner: -
392 399
--
393 400

  
......
5262 5269

  
5263 5270

  
5264 5271
--
5272
-- Name: taxondetermination_set_iscurrent; Type: TRIGGER; Schema: public; Owner: -
5273
--
5274

  
5275

  
5276

  
5277

  
5278
--
5265 5279
-- Name: taxonlabel_0_matched_label_id_self_ref; Type: TRIGGER; Schema: public; Owner: -
5266 5280
--
5267 5281

  
schemas/vegbien.sql
868 868

  
869 869

  
870 870
--
871
-- Name: taxondetermination_set_iscurrent(); Type: FUNCTION; Schema: public; Owner: -
872
--
873

  
874
CREATE FUNCTION taxondetermination_set_iscurrent() RETURNS trigger
875
    LANGUAGE plpgsql
876
    AS $$
877
BEGIN
878
    UPDATE taxondetermination SET iscurrent = false
879
    WHERE taxonoccurrence_id = new.taxonoccurrence_id AND iscurrent;
880
    
881
    UPDATE taxondetermination SET iscurrent = true
882
    WHERE taxondetermination_id = (
883
        SELECT taxondetermination_id FROM taxondetermination
884
        WHERE taxonoccurrence_id = new.taxonoccurrence_id
885
        ORDER BY isoriginal/*false first*/, determinationdate DESC NULLS LAST
886
        LIMIT 1
887
    );
888
    
889
    RETURN new;
890
END;
891
$$;
892

  
893

  
894
--
871 895
-- Name: taxonlabel_0_matched_label_id_self_ref(); Type: FUNCTION; Schema: public; Owner: -
872 896
--
873 897

  
......
6260 6284

  
6261 6285

  
6262 6286
--
6287
-- Name: taxondetermination_set_iscurrent; Type: TRIGGER; Schema: public; Owner: -
6288
--
6289

  
6290
CREATE TRIGGER taxondetermination_set_iscurrent AFTER INSERT ON taxondetermination FOR EACH ROW EXECUTE PROCEDURE taxondetermination_set_iscurrent();
6291

  
6292

  
6293
--
6263 6294
-- Name: taxonlabel_0_matched_label_id_self_ref; Type: TRIGGER; Schema: public; Owner: -
6264 6295
--
6265 6296

  

Also available in: Unified diff