Skip to content

Commit

Permalink
Simplify query
Browse files Browse the repository at this point in the history
  • Loading branch information
aaronfriedman6 committed Nov 5, 2024
1 parent 75bee9a commit 2c0eaf5
Showing 1 changed file with 6 additions and 12 deletions.
18 changes: 6 additions & 12 deletions helpers/query_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,17 @@
LIMIT {limit};"""

_SIERRA_QUERY = """
WITH phrase_barcodes AS (
SELECT record_id, index_entry
FROM sierra_view.phrase_entry
WHERE index_tag = 'b' AND record_id IN (
SELECT record_id
FROM sierra_view.phrase_entry
WHERE index_tag || index_entry IN ({})
)
)
SELECT
barcode, id, ptype_code, pcode3,
CASE WHEN LENGTH(TRIM(home_library_code)) = 0
OR TRIM(home_library_code) = 'none' THEN NULL
ELSE TRIM(home_library_code) END
FROM phrase_barcodes INNER JOIN sierra_view.patron_view
ON phrase_barcodes.record_id = patron_view.id
AND phrase_barcodes.index_entry = patron_view.barcode;"""
FROM sierra_view.patron_view
WHERE id IN (
SELECT record_id
FROM sierra_view.phrase_entry
WHERE index_tag || index_entry IN ({})
);"""

_REDSHIFT_QUERY = """
SELECT patron_id, postal_code, geoid
Expand Down

0 comments on commit 2c0eaf5

Please sign in to comment.