Compare commits
No commits in common. "d6dbf54ec6e81e519a0139f6a964c02f820f8f4b" and "55dcb65a171494727f4b92ade9f5d0cffbb59174" have entirely different histories.
d6dbf54ec6
...
55dcb65a17
@ -10,11 +10,11 @@ BEGIN
|
|||||||
SELECT
|
SELECT
|
||||||
-------------------------------------------create table---------------------------------------------------------------------------------------------------------
|
-------------------------------------------create table---------------------------------------------------------------------------------------------------------
|
||||||
'DROP TABLE IF EXISTS fc.'||func||' CASCADE; CREATE TABLE IF NOT EXISTS fc.'||func||' (' ||
|
'DROP TABLE IF EXISTS fc.'||func||' CASCADE; CREATE TABLE IF NOT EXISTS fc.'||func||' (' ||
|
||||||
string_agg(format('%I',cname) || ' ' || dtype,', ' ORDER BY CASE WHEN fkey IS NOT NULL THEN 0 ELSE opos END ASC) ||
|
string_agg(format('%I',cname) || ' ' || dtype,', ' ORDER BY opos ASC) ||
|
||||||
', PRIMARY KEY ('||string_agg(format('%I',cname),', ') FILTER (WHERE fkey = func)||'));' AS ddl,
|
', PRIMARY KEY ('||string_agg(format('%I',cname),', ') FILTER (WHERE fkey = func)||'));' AS ddl,
|
||||||
-------------------------------------------populate table-------------------------------------------------------------------------------------------------------
|
-------------------------------------------populate table-------------------------------------------------------------------------------------------------------
|
||||||
---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(format('%I',cname),', ' ORDER BY CASE WHEN fkey IS NOT NULL THEN 0 ELSE opos END ASC) || ' FROM '||tname||' WHERE '||
|
'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,
|
string_agg(format('%I',cname)||' IS NOT NULL ',' AND ') FILTER (WHERE fkey = func)||' ON CONFLICT DO NOTHING' AS pop,
|
||||||
-------------------------------------------setup foreign keys---------------------------------------------------------------------------------------------------
|
-------------------------------------------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||' ('||
|
'ALTER TABLE fc.live ADD CONSTRAINT fk_'||func||' FOREIGN KEY ('||string_agg(format('%I',cname),', ') FILTER (WHERE fkey = func)||') REFERENCES fc.'||func||' ('||
|
||||||
|
@ -7,7 +7,7 @@ BEGIN
|
|||||||
-------------------------------build a column list----------------------------------------
|
-------------------------------build a column list----------------------------------------
|
||||||
SELECT
|
SELECT
|
||||||
string_agg(
|
string_agg(
|
||||||
format('%I',cname) || CASE WHEN func IN ('odate','sdate') AND dtype = 'date' THEN ' + interval ''1 year''' ELSE '' END,E'\n,' ORDER BY opos ASC)
|
format('%I',cname) || CASE WHEN func IN ('odate','sdate') THEN ' + interval ''1 year''' ELSE '' END,E'\n,' ORDER BY opos ASC)
|
||||||
INTO
|
INTO
|
||||||
clist
|
clist
|
||||||
FROM
|
FROM
|
||||||
|
@ -9,7 +9,6 @@ CREATE TABLE fc.target_meta (
|
|||||||
,fkey text
|
,fkey text
|
||||||
,pretty text
|
,pretty text
|
||||||
,dtype text
|
,dtype text
|
||||||
,mastcol text
|
|
||||||
);
|
);
|
||||||
|
|
||||||
--ALTER TABLE fc.target_meta DROP CONSTRAINT IF EXISTS target_meta_pk;
|
--ALTER TABLE fc.target_meta DROP CONSTRAINT IF EXISTS target_meta_pk;
|
||||||
|
@ -3,14 +3,13 @@ BEGIN;
|
|||||||
INSERT INTO
|
INSERT INTO
|
||||||
fc.target_meta
|
fc.target_meta
|
||||||
SELECT
|
SELECT
|
||||||
table_schema||'.'||table_name
|
table_name
|
||||||
,column_name
|
,column_name
|
||||||
,ordinal_position
|
,ordinal_position
|
||||||
,'doc'::text func
|
,'doc'::text func
|
||||||
,null::text fkey --foreign key to a master table
|
,null::text fkey --foreign key to a master table
|
||||||
,null::text pretty
|
,null::text pretty
|
||||||
,data_type::text dtype
|
,data_type::text dtype
|
||||||
,column_name mastcol
|
|
||||||
FROM
|
FROM
|
||||||
information_schema.columns
|
information_schema.columns
|
||||||
WHERE
|
WHERE
|
||||||
|
Loading…
Reference in New Issue
Block a user