From 4b55ab4394194109502eef5c2a17d52b87fd043e Mon Sep 17 00:00:00 2001 From: Paul Trowbridge Date: Thu, 5 Nov 2020 22:39:36 -0500 Subject: [PATCH] put sql generating statemts into their own folder --- {sql => generate_sql}/baseline.sql | 0 {sql => generate_sql}/col_baseline.sql | 0 {sql => generate_sql}/col_interval.sql | 0 sql/temp.sql | 19 ------------------- 4 files changed, 19 deletions(-) rename {sql => generate_sql}/baseline.sql (100%) rename {sql => generate_sql}/col_baseline.sql (100%) rename {sql => generate_sql}/col_interval.sql (100%) delete mode 100644 sql/temp.sql diff --git a/sql/baseline.sql b/generate_sql/baseline.sql similarity index 100% rename from sql/baseline.sql rename to generate_sql/baseline.sql diff --git a/sql/col_baseline.sql b/generate_sql/col_baseline.sql similarity index 100% rename from sql/col_baseline.sql rename to generate_sql/col_baseline.sql diff --git a/sql/col_interval.sql b/generate_sql/col_interval.sql similarity index 100% rename from sql/col_interval.sql rename to generate_sql/col_interval.sql diff --git a/sql/temp.sql b/sql/temp.sql deleted file mode 100644 index 7a76bbc..0000000 --- a/sql/temp.sql +++ /dev/null @@ -1,19 +0,0 @@ - SELECT - -------------------------------------------create table--------------------------------------------------------------------------------------------------------- - 'DROP TABLE IF EXISTS fc.'||func||' CASCADE; CREATE TABLE IF NOT EXISTS fc.'||func||' (' || - string_agg(format('%I',cname) || ' ' || dtype,', ' ORDER BY opos ASC) || - ', PRIMARY KEY ('||string_agg(format('%I',cname),', ') FILTER (WHERE fkey = func)||'));' AS ddl, - -------------------------------------------populate table------------------------------------------------------------------------------------------------------- - ---need to add a clause to exclude where the key is null - 'INSERT INTO fc.'||func||' SELECT DISTINCT ' || string_agg(format('%I',cname),', ' ORDER BY opos ASC) || ' FROM '||tname||' WHERE '|| - string_agg(format('%I',cname)||' IS NOT NULL ',' AND ') FILTER (WHERE fkey = func)||' ON CONFLICT DO NOTHING' AS pop, - -------------------------------------------setup foreign keys--------------------------------------------------------------------------------------------------- - 'ALTER TABLE fc.live ADD CONSTRAINT fk_'||func||' FOREIGN KEY ('||string_agg(format('%I',cname),', ') FILTER (WHERE fkey = func)||') REFERENCES fc.'||func||' ('|| - string_agg(format('%I',cname),', ') FILTER (WHERE fkey = func)||')' AS fk - FROM - fc.target_meta - GROUP BY - tname - ,func - HAVING - string_agg(cname,', ') FILTER (WHERE fkey = func) <> ''