format the column name as an identity (%I) and only build statements where any fkey for a func is not null (dont build a master table for funcs with no primary key identified)
This commit is contained in:
parent
ae1a32baa7
commit
82f7a8fff2
@ -9,16 +9,16 @@ BEGIN
|
|||||||
FOR f IN
|
FOR f IN
|
||||||
SELECT
|
SELECT
|
||||||
'DROP TABLE IF EXISTS fc.'||func||'; CREATE TABLE IF NOT EXISTS fc.'||func||' (' ||
|
'DROP TABLE IF EXISTS fc.'||func||'; CREATE TABLE IF NOT EXISTS fc.'||func||' (' ||
|
||||||
string_agg(cname || ' ' || dtype,', ' ORDER BY opos ASC) ||
|
string_agg(format('%I',cname) || ' ' || dtype,', ' ORDER BY opos ASC) ||
|
||||||
', PRIMARY KEY ('||string_agg(cname,', ') FILTER (WHERE fkey = func)||'));' AS ddl,
|
', PRIMARY KEY ('||string_agg(format('%I',cname),', ') FILTER (WHERE fkey = func)||'));' AS ddl,
|
||||||
---need to add a clause to exclude where the key is null
|
---need to add a clause to exclude where the key is null
|
||||||
'INSERT INTO fc.'||func||' SELECT DISTINCT ' || string_agg(cname,', ' ORDER BY opos ASC) || ' FROM rlarp.osm_dev WHERE '||string_agg(cname,'||') FILTER (WHERE fkey = func)||' IS NOT NULL 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
|
FROM
|
||||||
fc.target_meta
|
fc.target_meta
|
||||||
WHERE
|
|
||||||
func <> 'doc'
|
|
||||||
GROUP BY
|
GROUP BY
|
||||||
func
|
func
|
||||||
|
HAVING
|
||||||
|
string_agg(cname,', ') FILTER (WHERE fkey = func) <> ''
|
||||||
loop
|
loop
|
||||||
EXECUTE format('%s',f.ddl);
|
EXECUTE format('%s',f.ddl);
|
||||||
EXECUTE format('%s',f.pop);
|
EXECUTE format('%s',f.pop);
|
||||||
|
10
sql/temp.sql
10
sql/temp.sql
@ -1,12 +1,12 @@
|
|||||||
SELECT
|
SELECT
|
||||||
'DROP TABLE IF EXISTS fc.'||func||'; CREATE TABLE IF NOT EXISTS fc.'||func||' (' ||
|
'DROP TABLE IF EXISTS fc.'||func||'; CREATE TABLE IF NOT EXISTS fc.'||func||' (' ||
|
||||||
string_agg(cname || ' ' || dtype,', ' ORDER BY opos ASC) ||
|
string_agg(format('%I',cname) || ' ' || dtype,', ' ORDER BY opos ASC) ||
|
||||||
', PRIMARY KEY ('||string_agg(cname,', ') FILTER (WHERE fkey = func)||'));' AS ddl,
|
', PRIMARY KEY ('||string_agg(format('%I',cname),', ') FILTER (WHERE fkey = func)||'));' AS ddl,
|
||||||
---need to add a clause to exclude where the key is null
|
---need to add a clause to exclude where the key is null
|
||||||
'INSERT INTO fc.'||func||' SELECT DISTINCT ' || string_agg(cname,', ' ORDER BY opos ASC) || ' FROM rlarp.osm_dev WHERE '||string_agg(cname,'||') FILTER (WHERE fkey = func)||' IS NOT NULL ON CONFLICT DO NOTHING' AS populate
|
'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
|
FROM
|
||||||
fc.target_meta
|
fc.target_meta
|
||||||
WHERE
|
|
||||||
func <> 'doc'
|
|
||||||
GROUP BY
|
GROUP BY
|
||||||
func
|
func
|
||||||
|
HAVING
|
||||||
|
string_agg(cname,', ') FILTER (WHERE fkey = func) <> ''
|
||||||
|
Loading…
Reference in New Issue
Block a user