Project

General

Profile

1 5491 aaronmk
SELECT *
2 5721 aaronmk
FROM "nodes.src"
3
JOIN "names.src" USING (tax_id)
4 5491 aaronmk
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 5820 aaronmk
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 5821 aaronmk
19 6033 aaronmk
-- Make name_txt (mostly) globally unique by removing other kingdoms
20 6032 aaronmk
-- Note that the delete will cascade to descendants
21 6033 aaronmk
DELETE FROM :table WHERE tax_id IN (
22
      10239 -- superkingdom Viruses
23
    , 12884 -- superkingdom Viroids
24
    , 12908 -- unclassified sequences
25
    , 28384 -- other sequences
26
    ,     2 -- superkingdom Bacteria
27
    ,  2157 -- superkingdom Archaea
28
    ,  4751 -- kingdom Fungi
29
    , 33208 -- kingdom Animalia/Metazoa
30
);
31 5835 aaronmk
32 6034 aaronmk
-- Make name_txt completely globally unique by removing duplicates
33 5835 aaronmk
DELETE FROM :table
34 6034 aaronmk
WHERE name_txt IN (
35 5835 aaronmk
    SELECT name_txt
36
    FROM :table
37
    GROUP BY name_txt
38
    HAVING count(*) > 1
39
)
40
;