create function jsonb_extract in tps schema
This commit is contained in:
parent
4b2851a61d
commit
b40f3edcda
@ -2,8 +2,8 @@
|
||||
-- PostgreSQL database dump
|
||||
--
|
||||
|
||||
-- Dumped from database version 10.2
|
||||
-- Dumped by pg_dump version 10.2
|
||||
-- Dumped from database version 10rc1
|
||||
-- Dumped by pg_dump version 10rc1
|
||||
|
||||
SET statement_timeout = 0;
|
||||
SET lock_timeout = 0;
|
||||
@ -82,6 +82,28 @@ END;
|
||||
$$;
|
||||
|
||||
|
||||
--
|
||||
-- Name: jsonb_extract(jsonb, text[]); Type: FUNCTION; Schema: tps; Owner: -
|
||||
--
|
||||
|
||||
CREATE FUNCTION jsonb_extract(rec jsonb, key_list text[]) RETURNS jsonb
|
||||
LANGUAGE plpgsql
|
||||
AS $$
|
||||
DECLARE
|
||||
t text[];
|
||||
j jsonb := '{}'::jsonb;
|
||||
|
||||
BEGIN
|
||||
FOREACH t SLICE 1 IN ARRAY key_list LOOP
|
||||
--RAISE NOTICE '%', t;
|
||||
--RAISE NOTICE '%', t[1];
|
||||
j := j || jsonb_build_object(t[1],rec#>t);
|
||||
END LOOP;
|
||||
RETURN j;
|
||||
END;
|
||||
$$;
|
||||
|
||||
|
||||
--
|
||||
-- Name: srce_set(text, jsonb); Type: FUNCTION; Schema: tps; Owner: -
|
||||
--
|
||||
|
@ -21,7 +21,7 @@ DECLARE _log_id text;
|
||||
|
||||
BEGIN
|
||||
|
||||
_path := 'C:\users\fleet\downloads\discover-recentactivity-20171031.csv';
|
||||
_path := 'C:\users\ptrowbridge\documents\tps_etl\sample_discovercard\data.csv';
|
||||
_srce := 'DCARD';
|
||||
|
||||
----------------------------------------------------build the column list of the temp table----------------------------------------------------------------
|
||||
@ -80,7 +80,7 @@ BEGIN
|
||||
|
||||
,pending_list AS (
|
||||
SELECT
|
||||
jsonb_extract(
|
||||
tps.jsonb_extract(
|
||||
row_to_json(i)::jsonb
|
||||
,ext.text_array
|
||||
) json_key,
|
||||
|
Loading…
Reference in New Issue
Block a user