Register
Login
Resources
Docs Blog Datasets Glossary Case Studies Tutorials & Webinars
Product
Data Engine LLMs Platform Enterprise
Pricing Explore
Connect to our Discord channel

gr-book-authors.sql 1.3 KB

You have to be logged in to leave a comment. Sign In
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
  1. --- #dep gr-books
  2. --- #dep gr-works
  3. --- #dep gr-authors
  4. --- #table gr.book_first_author
  5. --- #table gr.author_ids
  6. --- #step Extract book first authors
  7. CREATE MATERIALIZED VIEW IF NOT EXISTS gr.book_first_author AS
  8. SELECT gr_book_rid, role AS author_role, author_id AS gr_author_id
  9. FROM gr.raw_book, jsonb_to_record(gr_book_data->'authors'->0) AS
  10. x(role VARCHAR, author_id INTEGER);
  11. CREATE INDEX IF NOT EXISTS gr_bfa_book_idx ON gr.book_first_author (gr_book_rid);
  12. CREATE INDEX IF NOT EXISTS gr_bfa_auth_idx ON gr.book_first_author (gr_author_id);
  13. --- #step Extract book authors
  14. CREATE MATERIALIZED VIEW IF NOT EXISTS gr.book_authors AS
  15. SELECT gr_book_rid, role AS author_role, author_id AS gr_author_id
  16. FROM gr.raw_book, jsonb_to_recordset(gr_book_data->'authors') AS
  17. x(role VARCHAR, author_id INTEGER);
  18. CREATE INDEX IF NOT EXISTS gr_ba_book_idx ON gr.book_authors (gr_book_rid);
  19. CREATE INDEX IF NOT EXISTS gr_ba_auth_idx ON gr.book_authors (gr_author_id);
  20. --- #step Extract author IDs
  21. CREATE TABLE IF NOT EXISTS gr.author_ids
  22. AS SELECT gr_author_rid, (gr_author_data->>'author_id')::int AS gr_author_id
  23. FROM gr.raw_author;
  24. CREATE UNIQUE INDEX IF NOT EXISTS gr_author_ridx ON gr.author_ids (gr_author_rid);
  25. CREATE UNIQUE INDEX IF NOT EXISTS gr_author_idx ON gr.author_ids (gr_author_id);
Tip!

Press p or to see the previous file or, n or to see the next file

Comments

Loading...