and srce edit function
This commit is contained in:
parent
492e393723
commit
4b2851a61d
@ -1,6 +1,6 @@
|
|||||||
"C:\PostgreSQL\pg10\bin\psql" -h localhost -p 5433 -d postgres -U postgres -c "DROP DATABASE ubm"
|
"C:\PostgreSQL\pg10\bin\psql" -h localhost -p 5433 -d postgres -U postgres -c "DROP DATABASE ubm2"
|
||||||
"C:\PostgreSQL\pg10\bin\psql" -h localhost -p 5433 -d postgres -U postgres -c "CREATE DATABASE ubm"
|
"C:\PostgreSQL\pg10\bin\psql" -h localhost -p 5433 -d postgres -U postgres -c "CREATE DATABASE ubm2"
|
||||||
"C:\PostgreSQL\pg10\bin\psql" -h localhost -p 5433 -d ubm -U postgres -f "C:\users\fleet\documents\tps_etl\ubm_schema.sql"
|
"C:\PostgreSQL\pg10\bin\psql" -h localhost -p 5433 -d ubm2 -U postgres -f "C:\users\fleet\documents\tps_etl\ubm_schema.sql"
|
||||||
|
|
||||||
"/home/ubuntu/workspace/bigsql/pg10/bin/psql" -h localhost -p 5432 -d postgres -U postgres -c "DROP DATABASE ubm"
|
"/home/ubuntu/workspace/bigsql/pg10/bin/psql" -h localhost -p 5432 -d postgres -U postgres -c "DROP DATABASE ubm"
|
||||||
"/home/ubuntu/workspace/bigsql/pg10/bin/psql" -h localhost -p 5432 -d postgres -U postgres -c "CREATE DATABASE ubm"
|
"/home/ubuntu/workspace/bigsql/pg10/bin/psql" -h localhost -p 5432 -d postgres -U postgres -c "CREATE DATABASE ubm"
|
||||||
|
@ -82,6 +82,76 @@ END;
|
|||||||
$$;
|
$$;
|
||||||
|
|
||||||
|
|
||||||
|
--
|
||||||
|
-- Name: srce_set(text, jsonb); Type: FUNCTION; Schema: tps; Owner: -
|
||||||
|
--
|
||||||
|
|
||||||
|
CREATE FUNCTION srce_set(_name text, _defn jsonb) RETURNS jsonb
|
||||||
|
LANGUAGE plpgsql
|
||||||
|
AS $_$
|
||||||
|
|
||||||
|
DECLARE
|
||||||
|
_cnt int;
|
||||||
|
_conflict BOOLEAN;
|
||||||
|
_message jsonb;
|
||||||
|
|
||||||
|
BEGIN
|
||||||
|
|
||||||
|
/*
|
||||||
|
1. determine if insert or update
|
||||||
|
2. if update, determine if conflicts exists
|
||||||
|
3. do merge
|
||||||
|
*/
|
||||||
|
|
||||||
|
-------check for transctions already existing under this source-----------
|
||||||
|
SELECT
|
||||||
|
COUNT(*)
|
||||||
|
INTO
|
||||||
|
_cnt
|
||||||
|
FROM
|
||||||
|
tps.trans
|
||||||
|
WHERE
|
||||||
|
srce = _name;
|
||||||
|
|
||||||
|
-------set a message------------------------------------------------------
|
||||||
|
IF _cnt > 0 THEN
|
||||||
|
_conflict = TRUE;
|
||||||
|
--get out of the function somehow
|
||||||
|
_message =
|
||||||
|
$$
|
||||||
|
{
|
||||||
|
"message":"transactions already exist under source profile, cannot change the definition"
|
||||||
|
,"status":"error"
|
||||||
|
}
|
||||||
|
$$::jsonb;
|
||||||
|
return _message;
|
||||||
|
END IF;
|
||||||
|
|
||||||
|
/*-----------------schema validation---------------------
|
||||||
|
yeah dont feel like it right now
|
||||||
|
---------------------------------------------------------*/
|
||||||
|
|
||||||
|
INSERT INTO
|
||||||
|
tps.srce
|
||||||
|
SELECT
|
||||||
|
_name, _defn
|
||||||
|
ON CONFLICT ON CONSTRAINT srce_pkey DO UPDATE
|
||||||
|
SET
|
||||||
|
defn = _defn;
|
||||||
|
|
||||||
|
_message =
|
||||||
|
$$
|
||||||
|
{
|
||||||
|
"message":"definition set"
|
||||||
|
,"status":"success"
|
||||||
|
}
|
||||||
|
$$::jsonb;
|
||||||
|
return _message;
|
||||||
|
|
||||||
|
END;
|
||||||
|
$_$;
|
||||||
|
|
||||||
|
|
||||||
--
|
--
|
||||||
-- Name: jsonb_concat_obj(jsonb); Type: AGGREGATE; Schema: tps; Owner: -
|
-- Name: jsonb_concat_obj(jsonb); Type: AGGREGATE; Schema: tps; Owner: -
|
||||||
--
|
--
|
||||||
|
@ -29,7 +29,7 @@ BEGIN
|
|||||||
IF _cnt > 0 THEN
|
IF _cnt > 0 THEN
|
||||||
_conflict = TRUE;
|
_conflict = TRUE;
|
||||||
--get out of the function somehow
|
--get out of the function somehow
|
||||||
_message: =
|
_message =
|
||||||
$$
|
$$
|
||||||
{
|
{
|
||||||
"message":"transactions already exist under source profile, cannot change the definition"
|
"message":"transactions already exist under source profile, cannot change the definition"
|
||||||
@ -47,10 +47,18 @@ BEGIN
|
|||||||
tps.srce
|
tps.srce
|
||||||
SELECT
|
SELECT
|
||||||
_name, _defn
|
_name, _defn
|
||||||
ON CONFLICT DO UPDATE
|
ON CONFLICT ON CONSTRAINT srce_pkey DO UPDATE
|
||||||
SET
|
SET
|
||||||
defn = _defn;
|
defn = _defn;
|
||||||
|
|
||||||
|
_message =
|
||||||
|
$$
|
||||||
|
{
|
||||||
|
"message":"definition set"
|
||||||
|
,"status":"success"
|
||||||
|
}
|
||||||
|
$$::jsonb;
|
||||||
|
return _message;
|
||||||
|
|
||||||
END;
|
END;
|
||||||
$f$
|
$f$
|
||||||
|
Loading…
Reference in New Issue
Block a user