From 5bd3d4ee95dcb55bc7878d98b32002159af59de2 Mon Sep 17 00:00:00 2001 From: youainti Date: Thu, 2 Jun 2022 12:18:20 -0700 Subject: [PATCH] updated table definitions for views so that they deliver the correct information --- .../020_HttpSchema.sql | 27 ++++++++++++------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/AACT_downloader/ClinicalTrialHistory/docker-entrypoint-initdb.d/020_HttpSchema.sql b/AACT_downloader/ClinicalTrialHistory/docker-entrypoint-initdb.d/020_HttpSchema.sql index 48b4dc8..e45fe6d 100644 --- a/AACT_downloader/ClinicalTrialHistory/docker-entrypoint-initdb.d/020_HttpSchema.sql +++ b/AACT_downloader/ClinicalTrialHistory/docker-entrypoint-initdb.d/020_HttpSchema.sql @@ -92,14 +92,23 @@ Views to allow downloader programs to identify what to download. CREATE OR REPLACE VIEW http.most_recent_download_status AS - SELECT download_status.nct_id, - download_status.status, - max(download_status.update_timestamp) AS max - FROM http.download_status - GROUP BY download_status.nct_id, download_status.status; + SELECT t.nct_id, + t.status, + t.update_timestamp + FROM ( SELECT download_status.id, + download_status.nct_id, + download_status.status, + download_status.update_timestamp, + row_number() OVER (PARTITION BY download_status.nct_id ORDER BY download_status.update_timestamp DESC) AS rn + FROM http.download_status) t + WHERE t.rn = 1 + ORDER BY t.nct_id; ALTER TABLE http.most_recent_download_status - OWNER TO http_requestor; + OWNER TO root; +COMMENT ON VIEW http.most_recent_download_status + IS 'List of most recent download status'; + -- View: http.trials_to_download @@ -108,14 +117,12 @@ ALTER TABLE http.most_recent_download_status CREATE OR REPLACE VIEW http.trials_to_download AS - SELECT most_recent_download_status.nct_id, - most_recent_download_status.status, - most_recent_download_status.max + SELECT most_recent_download_status.nct_id FROM http.most_recent_download_status WHERE most_recent_download_status.status = 'Of Interest'::http.history_download_status; ALTER TABLE http.trials_to_download - OWNER TO http_requestor; + OWNER TO root; COMMENT ON VIEW http.trials_to_download IS 'List of trials for which the history needs downloaded';