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.4 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
29
30
31
32
  1. --- #dep gr-books
  2. --- #dep gr-works
  3. --- #dep gr-authors
  4. --- #table gr.book_first_author
  5. --- #table gr.author_info
  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. ANALYZE gr.book_first_author;
  14. --- #step Extract book authors
  15. CREATE MATERIALIZED VIEW IF NOT EXISTS gr.book_authors AS
  16. SELECT gr_book_rid, role AS author_role, author_id AS gr_author_id
  17. FROM gr.raw_book, jsonb_to_recordset(gr_book_data->'authors') AS
  18. x(role VARCHAR, author_id INTEGER);
  19. CREATE INDEX IF NOT EXISTS gr_ba_book_idx ON gr.book_authors (gr_book_rid);
  20. CREATE INDEX IF NOT EXISTS gr_ba_auth_idx ON gr.book_authors (gr_author_id);
  21. ANALYZE gr.book_authors;
  22. --- #step Extract author IDs
  23. CREATE TABLE IF NOT EXISTS gr.author_info
  24. AS SELECT gr_author_rid, (gr_author_data->>'author_id')::int AS gr_author_id,
  25. gr_author_data->>'name' AS author_name
  26. FROM gr.raw_author;
  27. CREATE UNIQUE INDEX IF NOT EXISTS gr_author_ridx ON gr.author_info (gr_author_rid);
  28. CREATE UNIQUE INDEX IF NOT EXISTS gr_author_idx ON gr.author_info (gr_author_id);
  29. ANALYZE gr.author_info;
Tip!

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

Comments

Loading...