add function to set map
This commit is contained in:
		
							parent
							
								
									e137977e94
								
							
						
					
					
						commit
						314d38ba3c
					
				| @ -363,6 +363,62 @@ END | |||||||
| $_$; | $_$; | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
|  | -- | ||||||
|  | -- Name: srce_map_def_set(text, text, jsonb, integer); Type: FUNCTION; Schema: tps; Owner: - | ||||||
|  | -- | ||||||
|  | 
 | ||||||
|  | CREATE FUNCTION srce_map_def_set(_srce text, _map text, _defn jsonb, _seq integer) RETURNS jsonb | ||||||
|  |     LANGUAGE plpgsql | ||||||
|  |     AS $_$ | ||||||
|  | 
 | ||||||
|  | DECLARE | ||||||
|  |     _message jsonb; | ||||||
|  |     _MESSAGE_TEXT text; | ||||||
|  |     _PG_EXCEPTION_DETAIL text; | ||||||
|  |     _PG_EXCEPTION_HINT text; | ||||||
|  | 
 | ||||||
|  | BEGIN | ||||||
|  | 
 | ||||||
|  |     BEGIN | ||||||
|  | 
 | ||||||
|  |         INSERT INTO | ||||||
|  |             tps.map_rm | ||||||
|  |         SELECT | ||||||
|  |             _srce | ||||||
|  |             ,_map | ||||||
|  |             ,_defn | ||||||
|  |             ,_seq | ||||||
|  |         ON CONFLICT ON CONSTRAINT map_rm_pk DO UPDATE SET | ||||||
|  |             srce = _srce | ||||||
|  |             ,target = _map | ||||||
|  |             ,regex = _defn | ||||||
|  |             ,seq = _seq; | ||||||
|  | 
 | ||||||
|  |     EXCEPTION WHEN OTHERS THEN | ||||||
|  | 
 | ||||||
|  |         GET STACKED DIAGNOSTICS  | ||||||
|  |                 _MESSAGE_TEXT = MESSAGE_TEXT, | ||||||
|  |                 _PG_EXCEPTION_DETAIL = PG_EXCEPTION_DETAIL, | ||||||
|  |                 _PG_EXCEPTION_HINT = PG_EXCEPTION_HINT; | ||||||
|  |             _message:=  | ||||||
|  |             ($$ | ||||||
|  |                 { | ||||||
|  |                     "status":"fail", | ||||||
|  |                     "message":"error setting definition" | ||||||
|  |                 } | ||||||
|  |             $$::jsonb) | ||||||
|  |             ||jsonb_build_object('message_text',_MESSAGE_TEXT) | ||||||
|  |             ||jsonb_build_object('pg_exception_detail',_PG_EXCEPTION_DETAIL); | ||||||
|  |             return _message; | ||||||
|  |     END; | ||||||
|  | 
 | ||||||
|  |     _message:= jsonb_build_object('status','complete','message','definition has been set'); | ||||||
|  |     return _message; | ||||||
|  | 
 | ||||||
|  | END; | ||||||
|  | $_$; | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
| -- | -- | ||||||
| -- Name: srce_set(text, jsonb); Type: FUNCTION; Schema: tps; Owner: - | -- Name: srce_set(text, jsonb); Type: FUNCTION; Schema: tps; Owner: - | ||||||
| -- | -- | ||||||
|  | |||||||
							
								
								
									
										51
									
								
								functions/srce_map_set.sql
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										51
									
								
								functions/srce_map_set.sql
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,51 @@ | |||||||
|  | CREATE OR REPLACE FUNCTION tps.srce_map_def_set(_srce text, _map text, _defn jsonb, _seq int) RETURNS jsonb | ||||||
|  | AS | ||||||
|  | $f$ | ||||||
|  | 
 | ||||||
|  | DECLARE | ||||||
|  |     _message jsonb; | ||||||
|  |     _MESSAGE_TEXT text; | ||||||
|  |     _PG_EXCEPTION_DETAIL text; | ||||||
|  |     _PG_EXCEPTION_HINT text; | ||||||
|  | 
 | ||||||
|  | BEGIN | ||||||
|  | 
 | ||||||
|  |     BEGIN | ||||||
|  | 
 | ||||||
|  |         INSERT INTO | ||||||
|  |             tps.map_rm | ||||||
|  |         SELECT | ||||||
|  |             _srce | ||||||
|  |             ,_map | ||||||
|  |             ,_defn | ||||||
|  |             ,_seq | ||||||
|  |         ON CONFLICT ON CONSTRAINT map_rm_pk DO UPDATE SET | ||||||
|  |             srce = _srce | ||||||
|  |             ,target = _map | ||||||
|  |             ,regex = _defn | ||||||
|  |             ,seq = _seq; | ||||||
|  | 
 | ||||||
|  |     EXCEPTION WHEN OTHERS THEN | ||||||
|  | 
 | ||||||
|  |         GET STACKED DIAGNOSTICS  | ||||||
|  |                 _MESSAGE_TEXT = MESSAGE_TEXT, | ||||||
|  |                 _PG_EXCEPTION_DETAIL = PG_EXCEPTION_DETAIL, | ||||||
|  |                 _PG_EXCEPTION_HINT = PG_EXCEPTION_HINT; | ||||||
|  |             _message:=  | ||||||
|  |             ($$ | ||||||
|  |                 { | ||||||
|  |                     "status":"fail", | ||||||
|  |                     "message":"error setting definition" | ||||||
|  |                 } | ||||||
|  |             $$::jsonb) | ||||||
|  |             ||jsonb_build_object('message_text',_MESSAGE_TEXT) | ||||||
|  |             ||jsonb_build_object('pg_exception_detail',_PG_EXCEPTION_DETAIL); | ||||||
|  |             return _message; | ||||||
|  |     END; | ||||||
|  | 
 | ||||||
|  |     _message:= jsonb_build_object('status','complete','message','definition has been set'); | ||||||
|  |     return _message; | ||||||
|  | 
 | ||||||
|  | END; | ||||||
|  | $f$ | ||||||
|  | language plpgsql | ||||||
| @ -79,11 +79,12 @@ map definition | |||||||
| 
 | 
 | ||||||
| SQL | SQL | ||||||
| --------------------------------------------- | --------------------------------------------- | ||||||
| INSERT INTO | select  | ||||||
|     tps.map_rm | 	x.x | ||||||
| SELECT | from | ||||||
|     'DCARD', | 	TPS.srce_map_def_set( | ||||||
|     'First 20', |     'DCARD'::text, | ||||||
|  |     'First 20'::text, | ||||||
|     $$    { |     $$    { | ||||||
|         "defn": [ |         "defn": [ | ||||||
|             { |             { | ||||||
| @ -103,7 +104,8 @@ SELECT | |||||||
|         "function": "extract", |         "function": "extract", | ||||||
|         "description": "pull first 20 characters from description for mapping" |         "description": "pull first 20 characters from description for mapping" | ||||||
|     } $$::jsonb, |     } $$::jsonb, | ||||||
|     1 |     1::int | ||||||
|  |     ) x(x) | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| assign new key/values to the results of the regular expression, and then back to the underlying row it came from | assign new key/values to the results of the regular expression, and then back to the underlying row it came from | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user