From 860b34fad86a8b6a485e41b8a370a6cb09089592 Mon Sep 17 00:00:00 2001 From: Paul Trowbridge Date: Thu, 22 Oct 2020 22:28:23 -0400 Subject: [PATCH] format so its not so long --- sql/build_master_tables.sql | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/sql/build_master_tables.sql b/sql/build_master_tables.sql index bcbbbac..5ffbf9c 100644 --- a/sql/build_master_tables.sql +++ b/sql/build_master_tables.sql @@ -8,11 +8,14 @@ DECLARE BEGIN FOR f IN SELECT + -------------------------------------------create table--------------------------------------------------------------------------------------------------------- 'DROP TABLE IF EXISTS fc.'||func||'; 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 rlarp.osm_dev WHERE '|| + string_agg(format('%I',cname)||' IS NOT NULL ',' AND ') FILTER (WHERE fkey = func)||' ON CONFLICT DO NOTHING' AS pop FROM fc.target_meta GROUP BY