Last active
February 11, 2021 19:18
-
-
Save asemic-horizon/a57a127613bcf7980c54e3be49b8ce9d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
```sql | |
create table documents ( | |
doc_id integer primary key, | |
content text | |
); | |
create table terms ( | |
term_id integer primary key, | |
term_name text, | |
parent_doc integer, | |
foreign key (parent_doc) references documents (doc_id) | |
); | |
create table citations ( | |
ref_id integer primary key, | |
doc_id integer, | |
term_id integer, | |
foreign key (doc_id) references documents (doc_id), | |
foreign key (term_id) references terms (term_id) | |
); | |
create view document_graph as | |
select | |
doc_id, parents.doc_id | |
from | |
documents | |
left join | |
citations on citations.doc_id = doc_id | |
left join | |
terms on terms.term_id = citations.term_id | |
left join | |
documents as parents on parents.doc_id = terms.doc_id; | |
``` | |
can |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment