~singpolyma/jmp-schemas

jmp-schemas/deploy/customers.sql -rw-r--r-- 427 bytes
395bb797Stephen Paul Weber Tag for notify on top up an expired account a month ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
-- Deploy jmp:customers to pg

BEGIN;

CREATE FOREIGN TABLE raw_customer_data (key text, val text)
	SERVER redis_server
	OPTIONS (tablekeyprefix 'jmp_customer_');

CREATE VIEW customers AS
	SELECT
		MAX(SPLIT_PART(key, '-', 2)) AS customer_id,
		JSONB_OBJECT_AGG(SUBSTRING(SPLIT_PART(key, '-', 1) FROM 14), val) AS data
	FROM raw_customer_data
	WHERE key NOT LIKE 'jmp_customer_id-%' GROUP BY SPLIT_PART(key, '-', 2);

COMMIT;