Project

General

Profile

« Previous | Next » 

Revision 6036

schemas/vegbien.sql: Added family_higher_plant_group lookup table, generated with make_family_higher_plant_group() using the contents of higher_plant_group_nodes

View differences:

schemas/vegbien.my.sql
243 243

  
244 244

  
245 245
--
246
-- Name: make_family_higher_plant_group(); Type: FUNCTION; Schema: public; Owner: -
247
--
248

  
249

  
250

  
251

  
252
--
246 253
-- Name: party_reference_id_self_ref(); Type: FUNCTION; Schema: public; Owner: -
247 254
--
248 255

  
......
1908 1915

  
1909 1916

  
1910 1917
--
1918
-- Name: family_higher_plant_group; Type: TABLE; Schema: public; Owner: -; Tablespace: 
1919
--
1920

  
1921
CREATE TABLE family_higher_plant_group (
1922
    family text NOT NULL,
1923
    higher_plant_group text
1924
);
1925

  
1926

  
1927
--
1911 1928
-- Name: geoscrub_input; Type: TABLE; Schema: public; Owner: -; Tablespace: 
1912 1929
--
1913 1930

  
......
3883 3900

  
3884 3901

  
3885 3902
--
3903
-- Data for Name: family_higher_plant_group; Type: TABLE DATA; Schema: public; Owner: -
3904
--
3905

  
3906

  
3907

  
3908

  
3909
--
3886 3910
-- Data for Name: geoscrub_input; Type: TABLE DATA; Schema: public; Owner: -
3887 3911
--
3888 3912

  
......
4379 4403

  
4380 4404

  
4381 4405
--
4406
-- Name: family_higher_plant_group_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace: 
4407
--
4408

  
4409
ALTER TABLE family_higher_plant_group
4410
    ADD CONSTRAINT family_higher_plant_group_pkey PRIMARY KEY (family);
4411

  
4412

  
4413
--
4382 4414
-- Name: graphic_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace: 
4383 4415
--
4384 4416

  
schemas/vegbien.sql
504 504

  
505 505

  
506 506
--
507
-- Name: make_family_higher_plant_group(); Type: FUNCTION; Schema: public; Owner: -
508
--
509

  
510
CREATE FUNCTION make_family_higher_plant_group() RETURNS void
511
    LANGUAGE plpgsql
512
    AS $$
513
DECLARE
514
    reference_id_ integer :=
515
        (SELECT reference_id FROM reference WHERE shortname = 'NCBI');
516
    row_ higher_plant_group_nodes%ROWTYPE;
517
BEGIN
518
    TRUNCATE family_higher_plant_group;
519
    
520
    FOR row_ IN
521
        SELECT * FROM higher_plant_group_nodes
522
        ORDER BY higher_plant_group, node_name
523
    LOOP
524
        DECLARE
525
            higher_plant_group_id integer := (
526
                SELECT taxonlabel_id FROM taxonlabel
527
                WHERE reference_id = reference_id_
528
                AND taxonomicname = row_.node_name
529
            );
530
            family text;
531
        BEGIN
532
            FOR family IN
533
                SELECT taxonepithet
534
                FROM taxonlabel_relationship
535
                JOIN taxonlabel ON taxonlabel_id = descendant_id
536
                WHERE ancestor_id = higher_plant_group_id
537
                AND rank = 'family'
538
                AND reference_id = reference_id_
539
            LOOP
540
                BEGIN
541
                    INSERT INTO family_higher_plant_group
542
                    VALUES (family, row_.higher_plant_group)
543
                    ;
544
                EXCEPTION
545
                    WHEN unique_violation THEN NULL;
546
                END;
547
            END LOOP;
548
        END;
549
    END LOOP;
550
END;
551
$$;
552

  
553

  
554
--
507 555
-- Name: party_reference_id_self_ref(); Type: FUNCTION; Schema: public; Owner: -
508 556
--
509 557

  
......
2614 2662

  
2615 2663

  
2616 2664
--
2665
-- Name: family_higher_plant_group; Type: TABLE; Schema: public; Owner: -; Tablespace: 
2666
--
2667

  
2668
CREATE TABLE family_higher_plant_group (
2669
    family text NOT NULL,
2670
    higher_plant_group higher_plant_group
2671
);
2672

  
2673

  
2674
--
2617 2675
-- Name: geoscrub_input; Type: TABLE; Schema: public; Owner: -; Tablespace: 
2618 2676
--
2619 2677

  
......
4835 4893

  
4836 4894

  
4837 4895
--
4896
-- Data for Name: family_higher_plant_group; Type: TABLE DATA; Schema: public; Owner: -
4897
--
4898

  
4899
COPY family_higher_plant_group (family, higher_plant_group) FROM stdin;
4900
\.
4901

  
4902

  
4903
--
4838 4904
-- Data for Name: geoscrub_input; Type: TABLE DATA; Schema: public; Owner: -
4839 4905
--
4840 4906

  
......
5391 5457

  
5392 5458

  
5393 5459
--
5460
-- Name: family_higher_plant_group_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace: 
5461
--
5462

  
5463
ALTER TABLE ONLY family_higher_plant_group
5464
    ADD CONSTRAINT family_higher_plant_group_pkey PRIMARY KEY (family);
5465

  
5466

  
5467
--
5394 5468
-- Name: graphic_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace: 
5395 5469
--
5396 5470

  

Also available in: Unified diff