515 |
515 |
$$;
|
516 |
516 |
|
517 |
517 |
|
|
518 |
SET default_tablespace = '';
|
|
519 |
|
|
520 |
SET default_with_oids = false;
|
|
521 |
|
518 |
522 |
--
|
|
523 |
-- Name: place; Type: TABLE; Schema: public; Owner: -; Tablespace:
|
|
524 |
--
|
|
525 |
|
|
526 |
CREATE TABLE place (
|
|
527 |
place_id integer NOT NULL,
|
|
528 |
reference_id integer NOT NULL,
|
|
529 |
placecode text,
|
|
530 |
canon_place_id integer,
|
|
531 |
matched_place_id integer,
|
|
532 |
coordinates_id integer,
|
|
533 |
placename_id integer,
|
|
534 |
continent text,
|
|
535 |
country text,
|
|
536 |
stateprovince text,
|
|
537 |
county text,
|
|
538 |
description text,
|
|
539 |
georeference_valid boolean,
|
|
540 |
distance_to_country_m double precision,
|
|
541 |
distance_to_state_m double precision,
|
|
542 |
CONSTRAINT place_required_key CHECK (((((((placecode IS NOT NULL) OR (coordinates_id IS NOT NULL)) OR (continent IS NOT NULL)) OR (country IS NOT NULL)) OR (stateprovince IS NOT NULL)) OR (county IS NOT NULL)))
|
|
543 |
);
|
|
544 |
|
|
545 |
|
|
546 |
--
|
|
547 |
-- Name: TABLE place; Type: COMMENT; Schema: public; Owner: -
|
|
548 |
--
|
|
549 |
|
|
550 |
COMMENT ON TABLE place IS 'The full path to a place. Can be either verbatim or accepted. For accepted names, points to the identified place.
|
|
551 |
|
|
552 |
To use a custom hierarchy of placenames with no explicit column, point to the lowest-rank placename in placename_id.';
|
|
553 |
|
|
554 |
|
|
555 |
--
|
|
556 |
-- Name: COLUMN place.matched_place_id; Type: COMMENT; Schema: public; Owner: -
|
|
557 |
--
|
|
558 |
|
|
559 |
COMMENT ON COLUMN place.matched_place_id IS 'The closest match to this place. Places should be linked in a three-level hierarchy of datasource place -> verbatim place -> accepted place.
|
|
560 |
|
|
561 |
An accepted place should point to itself in this field. This will happen automatically by setting it to the special value 0.';
|
|
562 |
|
|
563 |
|
|
564 |
--
|
|
565 |
-- Name: place_set_canon_place_id(place, integer, boolean); Type: FUNCTION; Schema: public; Owner: -
|
|
566 |
--
|
|
567 |
|
|
568 |
CREATE FUNCTION place_set_canon_place_id(new place, old_matched_place_id integer DEFAULT NULL::integer, is_update boolean DEFAULT false) RETURNS place
|
|
569 |
LANGUAGE plpgsql
|
|
570 |
AS $$
|
|
571 |
BEGIN
|
|
572 |
IF NOT is_update
|
|
573 |
OR new.matched_place_id IS DISTINCT FROM old_matched_place_id THEN
|
|
574 |
IF new.matched_place_id IS NOT NULL THEN
|
|
575 |
IF new.matched_place_id = new.place_id THEN -- self-reference
|
|
576 |
new.canon_place_id := new.place_id; -- make self-reference
|
|
577 |
ELSE -- propagate from matched place
|
|
578 |
new.canon_place_id := (
|
|
579 |
SELECT canon_place_id
|
|
580 |
FROM place
|
|
581 |
WHERE place_id = new.matched_place_id
|
|
582 |
);
|
|
583 |
END IF;
|
|
584 |
|
|
585 |
IF is_update THEN
|
|
586 |
-- Update canon_place_id on places that resolve to this place
|
|
587 |
UPDATE place
|
|
588 |
SET canon_place_id = new.canon_place_id
|
|
589 |
WHERE matched_place_id = new.place_id
|
|
590 |
AND place_id != new.place_id -- no infinite recursion
|
|
591 |
;
|
|
592 |
END IF;
|
|
593 |
ELSE -- no matched place
|
|
594 |
new.canon_place_id := new.place_id; -- make self-reference
|
|
595 |
END IF;
|
|
596 |
END IF;
|
|
597 |
|
|
598 |
RETURN new;
|
|
599 |
END;
|
|
600 |
$$;
|
|
601 |
|
|
602 |
|
|
603 |
--
|
|
604 |
-- Name: place_set_canon_place_id_on_insert(); Type: FUNCTION; Schema: public; Owner: -
|
|
605 |
--
|
|
606 |
|
|
607 |
CREATE FUNCTION place_set_canon_place_id_on_insert() RETURNS trigger
|
|
608 |
LANGUAGE plpgsql
|
|
609 |
AS $$
|
|
610 |
BEGIN
|
|
611 |
new := place_set_canon_place_id(new);
|
|
612 |
|
|
613 |
RETURN new;
|
|
614 |
END;
|
|
615 |
$$;
|
|
616 |
|
|
617 |
|
|
618 |
--
|
|
619 |
-- Name: place_set_canon_place_id_on_update(); Type: FUNCTION; Schema: public; Owner: -
|
|
620 |
--
|
|
621 |
|
|
622 |
CREATE FUNCTION place_set_canon_place_id_on_update() RETURNS trigger
|
|
623 |
LANGUAGE plpgsql
|
|
624 |
AS $$
|
|
625 |
BEGIN
|
|
626 |
new := place_set_canon_place_id(new, old.matched_place_id, true);
|
|
627 |
|
|
628 |
RETURN new;
|
|
629 |
END;
|
|
630 |
$$;
|
|
631 |
|
|
632 |
|
|
633 |
--
|
519 |
634 |
-- Name: placename_update_ancestors(); Type: FUNCTION; Schema: public; Owner: -
|
520 |
635 |
--
|
521 |
636 |
|
... | ... | |
689 |
804 |
$$;
|
690 |
805 |
|
691 |
806 |
|
692 |
|
SET default_tablespace = '';
|
693 |
|
|
694 |
|
SET default_with_oids = false;
|
695 |
|
|
696 |
807 |
--
|
697 |
808 |
-- Name: taxonlabel; Type: TABLE; Schema: public; Owner: -; Tablespace:
|
698 |
809 |
--
|
... | ... | |
1555 |
1666 |
|
1556 |
1667 |
|
1557 |
1668 |
--
|
1558 |
|
-- Name: place; Type: TABLE; Schema: public; Owner: -; Tablespace:
|
1559 |
|
--
|
1560 |
|
|
1561 |
|
CREATE TABLE place (
|
1562 |
|
place_id integer NOT NULL,
|
1563 |
|
reference_id integer NOT NULL,
|
1564 |
|
placecode text,
|
1565 |
|
canon_place_id integer,
|
1566 |
|
matched_place_id integer,
|
1567 |
|
coordinates_id integer,
|
1568 |
|
placename_id integer,
|
1569 |
|
continent text,
|
1570 |
|
country text,
|
1571 |
|
stateprovince text,
|
1572 |
|
county text,
|
1573 |
|
description text,
|
1574 |
|
georeference_valid boolean,
|
1575 |
|
distance_to_country_m double precision,
|
1576 |
|
distance_to_state_m double precision,
|
1577 |
|
CONSTRAINT place_required_key CHECK (((((((placecode IS NOT NULL) OR (coordinates_id IS NOT NULL)) OR (continent IS NOT NULL)) OR (country IS NOT NULL)) OR (stateprovince IS NOT NULL)) OR (county IS NOT NULL)))
|
1578 |
|
);
|
1579 |
|
|
1580 |
|
|
1581 |
|
--
|
1582 |
|
-- Name: TABLE place; Type: COMMENT; Schema: public; Owner: -
|
1583 |
|
--
|
1584 |
|
|
1585 |
|
COMMENT ON TABLE place IS 'The full path to a place. Can be either verbatim or accepted. For accepted names, points to the identified place.
|
1586 |
|
|
1587 |
|
To use a custom hierarchy of placenames with no explicit column, point to the lowest-rank placename in placename_id.';
|
1588 |
|
|
1589 |
|
|
1590 |
|
--
|
1591 |
|
-- Name: COLUMN place.matched_place_id; Type: COMMENT; Schema: public; Owner: -
|
1592 |
|
--
|
1593 |
|
|
1594 |
|
COMMENT ON COLUMN place.matched_place_id IS 'The closest match to this place. Places should be linked in a three-level hierarchy of datasource place -> verbatim place -> accepted place.
|
1595 |
|
|
1596 |
|
An accepted place should point to itself in this field. This will happen automatically by setting it to the special value 0.';
|
1597 |
|
|
1598 |
|
|
1599 |
|
--
|
1600 |
1669 |
-- Name: plantobservation; Type: TABLE; Schema: public; Owner: -; Tablespace:
|
1601 |
1670 |
--
|
1602 |
1671 |
|
... | ... | |
5240 |
5309 |
|
5241 |
5310 |
|
5242 |
5311 |
--
|
|
5312 |
-- Name: place_set_canon_place_id_on_insert; Type: TRIGGER; Schema: public; Owner: -
|
|
5313 |
--
|
|
5314 |
|
|
5315 |
CREATE TRIGGER place_set_canon_place_id_on_insert BEFORE INSERT ON place FOR EACH ROW EXECUTE PROCEDURE place_set_canon_place_id_on_insert();
|
|
5316 |
|
|
5317 |
|
|
5318 |
--
|
|
5319 |
-- Name: place_set_canon_place_id_on_update; Type: TRIGGER; Schema: public; Owner: -
|
|
5320 |
--
|
|
5321 |
|
|
5322 |
CREATE TRIGGER place_set_canon_place_id_on_update BEFORE UPDATE ON place FOR EACH ROW EXECUTE PROCEDURE place_set_canon_place_id_on_update();
|
|
5323 |
|
|
5324 |
|
|
5325 |
--
|
5243 |
5326 |
-- Name: placename_update_ancestors; Type: TRIGGER; Schema: public; Owner: -
|
5244 |
5327 |
--
|
5245 |
5328 |
|
schemas/vegbien.sql: place: Added place_set_canon_place_id_on_*() triggers, analogous to taxonlabel.taxonlabel_2_set_canon_label_id_on_*()