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

bx-index.sql 1014 B

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
  1. CREATE INDEX IF NOT EXISTS bx_rating_user_idx ON bx_ratings (user_id);
  2. CREATE INDEX IF NOT EXISTS bx_rating_isbn_idx ON bx_ratings (isbn);
  3. ANALYZE bx_ratings;
  4. INSERT INTO loc_isbn_book_id (isbn, book_id)
  5. WITH bad_isbns AS (SELECT DISTINCT isbn
  6. FROM bx_ratings br
  7. WHERE NOT EXISTS (SELECT * FROM loc_isbn_book_id ib WHERE ib.isbn = br.isbn))
  8. SELECT isbn, nextval('loc_synthetic_book_id') FROM bad_isbns;
  9. ANALYZE loc_isbn_book_id;
  10. DROP VIEW IF EXISTS bx_loc_explicit_ratings;
  11. CREATE VIEW bx_loc_explicit_ratings
  12. AS SELECT user_id, book_id, MEDIAN(rating) AS rating, COUNT(rating) AS nratings
  13. FROM bx_ratings
  14. JOIN loc_isbn_book_id USING (isbn)
  15. WHERE rating > 0
  16. GROUP BY user_id, book_id;
  17. DROP VIEW IF EXISTS bx_loc_all_ratings;
  18. CREATE VIEW bx_loc_all_ratings
  19. AS SELECT user_id, book_id, MEDIAN(rating) AS rating, COUNT(rating) AS nratings
  20. FROM bx_ratings
  21. JOIN loc_isbn_book_id USING (isbn)
  22. GROUP BY user_id, book_id;
Tip!

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

Comments

Loading...