From 898593c3a859fedfd99e49d4686569f8639b76dd Mon Sep 17 00:00:00 2001 From: Paul Trowbridge Date: Fri, 13 May 2022 13:35:50 -0400 Subject: [PATCH] put sample data table in separate file and use target table in new table creation --- setup_sql/01_sample.sql | 1 + setup_sql/01_schema.sql | 1 - setup_sql/03_build_master_tables.sql | 2 +- 3 files changed, 2 insertions(+), 2 deletions(-) create mode 100644 setup_sql/01_sample.sql diff --git a/setup_sql/01_sample.sql b/setup_sql/01_sample.sql new file mode 100644 index 0000000..eec4952 --- /dev/null +++ b/setup_sql/01_sample.sql @@ -0,0 +1 @@ +CREATE TABLE fc.dcard AS (SELECT * FROM tpsv.dcard_mapped) WITH DATA; diff --git a/setup_sql/01_schema.sql b/setup_sql/01_schema.sql index 92caf22..ec666d3 100644 --- a/setup_sql/01_schema.sql +++ b/setup_sql/01_schema.sql @@ -1,6 +1,5 @@ DROP SCHEMA fc CASCADE; CREATE SCHEMA IF NOT EXISTS fc; -CREATE TABLE fc.dcard AS (SELECT * FROM tpsv.dcard_mapped) WITH DATA; --DROP TABLE IF EXISTS fc.target_meta; CREATE TABLE IF NOT EXISTS fc.target_meta ( diff --git a/setup_sql/03_build_master_tables.sql b/setup_sql/03_build_master_tables.sql index 021d8a8..44979b8 100644 --- a/setup_sql/03_build_master_tables.sql +++ b/setup_sql/03_build_master_tables.sql @@ -36,7 +36,7 @@ BEGIN --HAVING -- string_agg(cname,', ') FILTER (WHERE fkey = func) <> '' loop - INSERT INTO fc.sql SELECT f.func, f.ddl ON CONFLICT ON CONSTRAINT sql_pkey DO UPDATE SET t = EXCLUDED.t; + INSERT INTO fc.sql SELECT _target_table, f.func, f.ddl ON CONFLICT ON CONSTRAINT sql_pkey DO UPDATE SET t = EXCLUDED.t; EXECUTE format('%s',f.ddl); EXECUTE format('%s',f.pop); EXECUTE format('%s',f.fk);