From fb76e42e42e60bac2c4095fc2042c7717fbb0eb5 Mon Sep 17 00:00:00 2001 From: Paul Trowbridge Date: Thu, 22 Oct 2020 23:09:34 -0400 Subject: [PATCH] update temp, it just mirrors build query for testing --- sql/temp.sql | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/sql/temp.sql b/sql/temp.sql index ee6f28a..7a76bbc 100644 --- a/sql/temp.sql +++ b/sql/temp.sql @@ -1,12 +1,19 @@ SELECT - 'DROP TABLE IF EXISTS fc.'||func||'; CREATE TABLE IF NOT EXISTS fc.'||func||' (' || + -------------------------------------------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 rlarp.osm_dev WHERE '||string_agg(format('%I',cname)||' IS NOT NULL ',' AND ') FILTER (WHERE fkey = func)||' ON CONFLICT DO NOTHING' AS pop + '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 - func + tname + ,func HAVING string_agg(cname,', ') FILTER (WHERE fkey = func) <> ''