Project

General

Profile

1
SELECT *
2
FROM "nodes.src"
3
JOIN "names.src" USING (tax_id)
4
WHERE "name class" = 'scientific name'
5
;
6

    
7
ALTER TABLE :table ALTER COLUMN tax_id TYPE integer
8
USING tax_id::integer;
9
ALTER TABLE :table ALTER COLUMN "parent tax_id" TYPE integer
10
USING "parent tax_id"::integer;
11

    
12
ALTER TABLE :table ADD PRIMARY KEY (tax_id);
13

    
14
CREATE INDEX ON :table ("parent tax_id");
15

    
16
ALTER TABLE :table ADD FOREIGN KEY ("parent tax_id") REFERENCES :table (tax_id)
17
    ON UPDATE CASCADE ON DELETE CASCADE;
18

    
19
-- Make genus (mostly) globally unique by removing other kingdoms
20
-- Note that the delete will cascade to descendants
21
DELETE FROM :table WHERE tax_id = 33208; -- kingdom Animalia/Metazoa
22

    
23
-- Make genus completely globally unique by removing duplicates
24
DELETE FROM :table
25
WHERE rank IN ('genus', 'subgenus')
26
AND name_txt IN (
27
    SELECT name_txt
28
    FROM :table
29
    WHERE rank IN ('genus', 'subgenus')
30
    GROUP BY name_txt
31
    HAVING count(*) > 1
32
)
33
;
(3-3/8)