prevent inserting null keys, and conflicting keys which is possible with disperate master data (maybe use max?)
This commit is contained in:
parent
ba3d9e682e
commit
511a38faf9
@ -12,7 +12,7 @@ BEGIN
|
|||||||
string_agg(cname || ' ' || dtype,', ' ORDER BY opos ASC) ||
|
string_agg(cname || ' ' || dtype,', ' ORDER BY opos ASC) ||
|
||||||
', PRIMARY KEY ('||string_agg(cname,', ') FILTER (WHERE fkey = func)||'));' AS ddl,
|
', PRIMARY KEY ('||string_agg(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' AS populate
|
'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
|
||||||
FROM
|
FROM
|
||||||
fc.target_meta
|
fc.target_meta
|
||||||
WHERE
|
WHERE
|
||||||
|
17
sql/temp.sql
17
sql/temp.sql
@ -1,11 +1,12 @@
|
|||||||
SELECT
|
SELECT
|
||||||
'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(cname || ' ' || dtype,', ' ORDER BY opos ASC) ||
|
||||||
', PRIMARY KEY ('||string_agg(cname,', ') FILTER (WHERE fkey = func)||'))' AS ddl,
|
', PRIMARY KEY ('||string_agg(cname,', ') FILTER (WHERE fkey = func)||'));' AS ddl,
|
||||||
'INSERT INTO fc.'||func||' SELECT DISTINCT ' || string_agg(cname,', ' ORDER BY opos ASC) || ' FROM fc.target' AS populate
|
---need to add a clause to exclude where the key is null
|
||||||
FROM
|
'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
|
||||||
|
FROM
|
||||||
fc.target_meta
|
fc.target_meta
|
||||||
WHERE
|
WHERE
|
||||||
func <> 'doc'
|
func <> 'doc'
|
||||||
GROUP BY
|
GROUP BY
|
||||||
func;
|
func
|
||||||
|
Loading…
Reference in New Issue
Block a user