aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--sql/et_tables.sql13
1 files changed, 3 insertions, 10 deletions
diff --git a/sql/et_tables.sql b/sql/et_tables.sql
index f0cfbee9..d2f192ae 100644
--- a/sql/et_tables.sql
+++ b/sql/et_tables.sql
@@ -516,17 +516,10 @@ bloomberg_corp USING (figi) ORDER BY figi, pricingdate DESC;
CREATE OR REPLACE FUNCTION historical_bloomberg_corp(p_date date)
RETURNS SETOF latest_bloomberg_corp AS $$
BEGIN
- RETURN QUERY SELECT b.pricingdate, CASE
- WHEN c.cusip is NULL THEN substring(id_bb_unique from 3)::varchar(9)
- ELSE c.cusip
- END, b.price,
- c.issuer, c.issue_size, b.amount_outstanding, c.covlite, c.secondlien, c.defaulted FROM
- (SELECT MAX(pricingdate) AS pricingdate, id_bb_unique FROM bloomberg_corp WHERE
- pricingdate<=p_date GROUP BY id_bb_unique) a
- JOIN bloomberg_corp b USING (id_bb_unique, pricingdate) JOIN bloomberg_corp_ref c
- USING (id_bb_unique);
+ RETURN QUERY SELECT DISTINCT ON (figi) * FROM bloomberg_corp_ref JOIN bloomberg_corp USING (figi)
+ WHERE pricingdate <=p_date ORDER BY figi, pricingdate DESC;
END;
- $$ LANGUAGE plpgsql;
+$$ LANGUAGE plpgsql;
-- CREATE OR REPLACE FUNCTION historical_bloomberg_mtge(p_date date)
-- RETURNS TABLE(CUSIP varchar(9), updatedate date, issuer text, maturity date,