diff options
Diffstat (limited to 'sql/serenitasdb.sql')
| -rw-r--r-- | sql/serenitasdb.sql | 20 |
1 files changed, 16 insertions, 4 deletions
diff --git a/sql/serenitasdb.sql b/sql/serenitasdb.sql index 3f7cb751..a562ff8a 100644 --- a/sql/serenitasdb.sql +++ b/sql/serenitasdb.sql @@ -437,6 +437,17 @@ RETURNS SETOF cds_issuers_weight AS $$ END;
$$ LANGUAGE plpgsql;
+CREATE OR REPLACE FUNCTION index_curves(index_name varchar(4), p_date date)
+RETURNS TABLE(weight float, p_curve bytea) AS $$
+ DECLARE
+ p_basketid integer;
+ BEGIN
+ SELECT nameToBasketID(index_name, p_date) INTO p_basketid;
+ RETURN QUERY SELECT curr_weight, curve FROM basket_constituents_current
+ LEFT JOIN cds_curves USING (company_id, seniority)
+ WHERE basketid=p_basketid and date=p_date;
+ END;
+$$ LANGUAGE plpgsql;
CREATE OR REPLACE FUNCTION historical_cds_quotes(date, bbgSource) RETURNS SETOF cds_quotes AS $$
BEGIN
@@ -910,11 +921,12 @@ CREATE TABLE JPY_curves( curve bytea);
CREATE TABLE cds_curves(
- date date,
- id integer,
- seniority sen,
- curve bytea,
+ date date NOT NULL,
+ company_id integer NOT NULL,
+ seniority sen NOT NULL,
+ curve bytea NOT NULL,
FOREIGN KEY (id, seniority) REFERENCES bbg_issuers
+ PRIMARY KEY (date, company_id, seniority)
)
|
