Merge pull request #39 from fleetside72/not_inserting
fix failure to insert
This commit is contained in:
commit
27582dee4f
@ -2054,17 +2054,18 @@ DECLARE
|
|||||||
_PG_EXCEPTION_DETAIL text;
|
_PG_EXCEPTION_DETAIL text;
|
||||||
_PG_EXCEPTION_HINT text;
|
_PG_EXCEPTION_HINT text;
|
||||||
_rebuild BOOLEAN;
|
_rebuild BOOLEAN;
|
||||||
|
_list text;
|
||||||
BEGIN
|
BEGIN
|
||||||
|
|
||||||
WITH
|
WITH
|
||||||
--retain the results of the update by srce
|
--retain the results of the update by srce
|
||||||
_set AS (
|
_set AS (
|
||||||
SELECT
|
SELECT
|
||||||
j.rn rn
|
j.rn rn
|
||||||
,j.e->>'name' srce
|
,j.e->>'name' srce
|
||||||
,j.e defn
|
,j.e defn
|
||||||
FROM
|
FROM
|
||||||
jsonb_array_elements(_defn) WITH ORDINALITY j(e, rn)
|
jsonb_array_elements(_defn) WITH ORDINALITY j(e, rn)
|
||||||
)
|
)
|
||||||
--full join
|
--full join
|
||||||
,_full AS (
|
,_full AS (
|
||||||
@ -2078,29 +2079,55 @@ BEGIN
|
|||||||
_set.srce = _srce.srce
|
_set.srce = _srce.srce
|
||||||
)
|
)
|
||||||
--call functions from list
|
--call functions from list
|
||||||
,_do AS (
|
,_do_set AS (
|
||||||
SELECT
|
SELECT
|
||||||
f.srce
|
f.srce
|
||||||
,f.actn
|
,f.actn
|
||||||
,COALESCE(setd.message, deld.message) message
|
,setd.message
|
||||||
FROM
|
FROM
|
||||||
_full f
|
_full f
|
||||||
LEFT JOIN LATERAL tps.srce_set(defn) setd(message) ON f.actn = 'SET'
|
JOIN LATERAL tps.srce_set(defn) setd(message) ON f.actn = 'SET'
|
||||||
LEFT JOIN LATERAL tps.srce_delete(defn) deld(message) ON f.actn = 'DELETE'
|
--dual left joins for functions that touch the same table causes the first left join actions to be undone
|
||||||
|
--LEFT JOIN LATERAL tps.srce_delete(defn) deld(message) ON f.actn = 'DELETE'
|
||||||
|
)
|
||||||
|
,_do_del AS (
|
||||||
|
SELECT
|
||||||
|
f.srce
|
||||||
|
,f.actn
|
||||||
|
,deld.message
|
||||||
|
FROM
|
||||||
|
_full f
|
||||||
|
JOIN LATERAL tps.srce_delete(defn) deld(message) ON f.actn = 'DELETE'
|
||||||
)
|
)
|
||||||
--aggregate all the messages into one message
|
--aggregate all the messages into one message
|
||||||
----
|
----
|
||||||
---- should look at rolling back the whole thing if one of the function returns a fail. stored proc could do this.
|
---- should look at rolling back the whole thing if one of the function returns a fail. stored proc could do this.
|
||||||
----
|
----
|
||||||
SELECT
|
SELECT
|
||||||
jsonb_agg(jsonb_build_object('source',srce,'status',message->>'status','message',message->>'message'))
|
jsonb_agg(m)
|
||||||
INTO
|
INTO
|
||||||
_message
|
_message
|
||||||
FROM
|
FROM
|
||||||
_do;
|
(
|
||||||
|
SELECT
|
||||||
|
jsonb_build_object('source',srce,'status',message->>'status','message',message->>'message') m
|
||||||
|
FROM
|
||||||
|
_do_set
|
||||||
|
UNION ALL
|
||||||
|
SELECT
|
||||||
|
jsonb_build_object('source',srce,'status',message->>'status','message',message->>'message') m
|
||||||
|
FROM
|
||||||
|
_do_del
|
||||||
|
) x;
|
||||||
|
|
||||||
|
SELECT string_agg(srce,',') INTO _list FROM tps.srce;
|
||||||
|
RAISE NOTICE 'multi source list: %', _list;
|
||||||
|
|
||||||
RETURN _message;
|
RETURN _message;
|
||||||
|
|
||||||
|
SELECT string_agg(srce,',') INTO _list FROM tps.srce;
|
||||||
|
RAISE NOTICE 'after return: %', _list;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
EXCEPTION WHEN OTHERS THEN
|
EXCEPTION WHEN OTHERS THEN
|
||||||
@ -2120,4 +2147,4 @@ BEGIN
|
|||||||
RETURN _message;
|
RETURN _message;
|
||||||
END;
|
END;
|
||||||
$f$
|
$f$
|
||||||
LANGUAGE plpgsql;
|
LANGUAGE plpgsql
|
@ -12,17 +12,18 @@ DECLARE
|
|||||||
_PG_EXCEPTION_DETAIL text;
|
_PG_EXCEPTION_DETAIL text;
|
||||||
_PG_EXCEPTION_HINT text;
|
_PG_EXCEPTION_HINT text;
|
||||||
_rebuild BOOLEAN;
|
_rebuild BOOLEAN;
|
||||||
|
_list text;
|
||||||
BEGIN
|
BEGIN
|
||||||
|
|
||||||
WITH
|
WITH
|
||||||
--retain the results of the update by srce
|
--retain the results of the update by srce
|
||||||
_set AS (
|
_set AS (
|
||||||
SELECT
|
SELECT
|
||||||
j.rn rn
|
j.rn rn
|
||||||
,j.e->>'name' srce
|
,j.e->>'name' srce
|
||||||
,j.e defn
|
,j.e defn
|
||||||
FROM
|
FROM
|
||||||
jsonb_array_elements(_defn) WITH ORDINALITY j(e, rn)
|
jsonb_array_elements(_defn) WITH ORDINALITY j(e, rn)
|
||||||
)
|
)
|
||||||
--full join
|
--full join
|
||||||
,_full AS (
|
,_full AS (
|
||||||
@ -36,29 +37,55 @@ BEGIN
|
|||||||
_set.srce = _srce.srce
|
_set.srce = _srce.srce
|
||||||
)
|
)
|
||||||
--call functions from list
|
--call functions from list
|
||||||
,_do AS (
|
,_do_set AS (
|
||||||
SELECT
|
SELECT
|
||||||
f.srce
|
f.srce
|
||||||
,f.actn
|
,f.actn
|
||||||
,COALESCE(setd.message, deld.message) message
|
,setd.message
|
||||||
FROM
|
FROM
|
||||||
_full f
|
_full f
|
||||||
LEFT JOIN LATERAL tps.srce_set(defn) setd(message) ON f.actn = 'SET'
|
JOIN LATERAL tps.srce_set(defn) setd(message) ON f.actn = 'SET'
|
||||||
LEFT JOIN LATERAL tps.srce_delete(defn) deld(message) ON f.actn = 'DELETE'
|
--dual left joins for functions that touch the same table causes the first left join actions to be undone
|
||||||
|
--LEFT JOIN LATERAL tps.srce_delete(defn) deld(message) ON f.actn = 'DELETE'
|
||||||
|
)
|
||||||
|
,_do_del AS (
|
||||||
|
SELECT
|
||||||
|
f.srce
|
||||||
|
,f.actn
|
||||||
|
,deld.message
|
||||||
|
FROM
|
||||||
|
_full f
|
||||||
|
JOIN LATERAL tps.srce_delete(defn) deld(message) ON f.actn = 'DELETE'
|
||||||
)
|
)
|
||||||
--aggregate all the messages into one message
|
--aggregate all the messages into one message
|
||||||
----
|
----
|
||||||
---- should look at rolling back the whole thing if one of the function returns a fail. stored proc could do this.
|
---- should look at rolling back the whole thing if one of the function returns a fail. stored proc could do this.
|
||||||
----
|
----
|
||||||
SELECT
|
SELECT
|
||||||
jsonb_agg(jsonb_build_object('source',srce,'status',message->>'status','message',message->>'message'))
|
jsonb_agg(m)
|
||||||
INTO
|
INTO
|
||||||
_message
|
_message
|
||||||
FROM
|
FROM
|
||||||
_do;
|
(
|
||||||
|
SELECT
|
||||||
|
jsonb_build_object('source',srce,'status',message->>'status','message',message->>'message') m
|
||||||
|
FROM
|
||||||
|
_do_set
|
||||||
|
UNION ALL
|
||||||
|
SELECT
|
||||||
|
jsonb_build_object('source',srce,'status',message->>'status','message',message->>'message') m
|
||||||
|
FROM
|
||||||
|
_do_del
|
||||||
|
) x;
|
||||||
|
|
||||||
|
SELECT string_agg(srce,',') INTO _list FROM tps.srce;
|
||||||
|
RAISE NOTICE 'multi source list: %', _list;
|
||||||
|
|
||||||
RETURN _message;
|
RETURN _message;
|
||||||
|
|
||||||
|
SELECT string_agg(srce,',') INTO _list FROM tps.srce;
|
||||||
|
RAISE NOTICE 'after return: %', _list;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
EXCEPTION WHEN OTHERS THEN
|
EXCEPTION WHEN OTHERS THEN
|
||||||
|
@ -12,17 +12,18 @@ DECLARE
|
|||||||
_PG_EXCEPTION_DETAIL text;
|
_PG_EXCEPTION_DETAIL text;
|
||||||
_PG_EXCEPTION_HINT text;
|
_PG_EXCEPTION_HINT text;
|
||||||
_rebuild BOOLEAN;
|
_rebuild BOOLEAN;
|
||||||
|
_list text;
|
||||||
BEGIN
|
BEGIN
|
||||||
|
|
||||||
WITH
|
WITH
|
||||||
--retain the results of the update by srce
|
--retain the results of the update by srce
|
||||||
_set AS (
|
_set AS (
|
||||||
SELECT
|
SELECT
|
||||||
j.rn rn
|
j.rn rn
|
||||||
,j.e->>'name' srce
|
,j.e->>'name' srce
|
||||||
,j.e defn
|
,j.e defn
|
||||||
FROM
|
FROM
|
||||||
jsonb_array_elements(_defn) WITH ORDINALITY j(e, rn)
|
jsonb_array_elements(_defn) WITH ORDINALITY j(e, rn)
|
||||||
)
|
)
|
||||||
--full join
|
--full join
|
||||||
,_full AS (
|
,_full AS (
|
||||||
@ -36,29 +37,55 @@ BEGIN
|
|||||||
_set.srce = _srce.srce
|
_set.srce = _srce.srce
|
||||||
)
|
)
|
||||||
--call functions from list
|
--call functions from list
|
||||||
,_do AS (
|
,_do_set AS (
|
||||||
SELECT
|
SELECT
|
||||||
f.srce
|
f.srce
|
||||||
,f.actn
|
,f.actn
|
||||||
,COALESCE(setd.message, deld.message) message
|
,setd.message
|
||||||
FROM
|
FROM
|
||||||
_full f
|
_full f
|
||||||
LEFT JOIN LATERAL tps.srce_set(defn) setd(message) ON f.actn = 'SET'
|
JOIN LATERAL tps.srce_set(defn) setd(message) ON f.actn = 'SET'
|
||||||
LEFT JOIN LATERAL tps.srce_delete(defn) deld(message) ON f.actn = 'DELETE'
|
--dual left joins for functions that touch the same table causes the first left join actions to be undone
|
||||||
|
--LEFT JOIN LATERAL tps.srce_delete(defn) deld(message) ON f.actn = 'DELETE'
|
||||||
|
)
|
||||||
|
,_do_del AS (
|
||||||
|
SELECT
|
||||||
|
f.srce
|
||||||
|
,f.actn
|
||||||
|
,deld.message
|
||||||
|
FROM
|
||||||
|
_full f
|
||||||
|
JOIN LATERAL tps.srce_delete(defn) deld(message) ON f.actn = 'DELETE'
|
||||||
)
|
)
|
||||||
--aggregate all the messages into one message
|
--aggregate all the messages into one message
|
||||||
----
|
----
|
||||||
---- should look at rolling back the whole thing if one of the function returns a fail. stored proc could do this.
|
---- should look at rolling back the whole thing if one of the function returns a fail. stored proc could do this.
|
||||||
----
|
----
|
||||||
SELECT
|
SELECT
|
||||||
jsonb_agg(jsonb_build_object('source',srce,'status',message->>'status','message',message->>'message'))
|
jsonb_agg(m)
|
||||||
INTO
|
INTO
|
||||||
_message
|
_message
|
||||||
FROM
|
FROM
|
||||||
_do;
|
(
|
||||||
|
SELECT
|
||||||
|
jsonb_build_object('source',srce,'status',message->>'status','message',message->>'message') m
|
||||||
|
FROM
|
||||||
|
_do_set
|
||||||
|
UNION ALL
|
||||||
|
SELECT
|
||||||
|
jsonb_build_object('source',srce,'status',message->>'status','message',message->>'message') m
|
||||||
|
FROM
|
||||||
|
_do_del
|
||||||
|
) x;
|
||||||
|
|
||||||
|
SELECT string_agg(srce,',') INTO _list FROM tps.srce;
|
||||||
|
RAISE NOTICE 'multi source list: %', _list;
|
||||||
|
|
||||||
RETURN _message;
|
RETURN _message;
|
||||||
|
|
||||||
|
SELECT string_agg(srce,',') INTO _list FROM tps.srce;
|
||||||
|
RAISE NOTICE 'after return: %', _list;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
EXCEPTION WHEN OTHERS THEN
|
EXCEPTION WHEN OTHERS THEN
|
||||||
|
Loading…
Reference in New Issue
Block a user