diff --git a/sample_discovercard/definition.md b/sample_discovercard/definition.md index 2a14112..d22ba71 100644 --- a/sample_discovercard/definition.md +++ b/sample_discovercard/definition.md @@ -91,6 +91,51 @@ screen builds json } } +SQL +--------------------------------------- +SELECT + jsonb_pretty(r.x) +FROM + tps.srce_set( + 'DCARD', + $$ + { + "name": "DCARD", + "type": "csv", + "schema": [ + { + "key": "Trans. Date", + "type": "date" + }, + { + "key": "Post Date", + "type": "date" + }, + { + "key": "Description", + "type": "text" + }, + { + "key": "Amount", + "type": "numeric" + }, + { + "key": "Category", + "type": "text" + } + ], + "unique_constraint": { + "type": "key", + "fields": [ + "{Post Date}", + "{Trans. Date}", + "{Description}" + ] + } + } + $$ +) r(x) + backend handles SQL ----------------------------------- diff --git a/sample_discovercard/mapping.md b/sample_discovercard/mapping.md index 3322020..73f5f1f 100644 --- a/sample_discovercard/mapping.md +++ b/sample_discovercard/mapping.md @@ -77,6 +77,33 @@ map definition "description": "pull first 20 characters from description for mapping" } +SQL +--------------------------------------------- +INSERT INTO + tps.map_rm +SELECT + 'DCARD', + 'First 20', + $$ { + "defn": [ + { + "key": "{Description}", + "map": "y", + "flag": "g", + "field": "f20", + "regex": ".{1,20}", + "retain": "y" + } + ], + "name": "First 20", + "where": [ + {"Category":"Restaurantes"}, + {"Category":"Services"} + ], + "function": "extract", + "description": "pull first 20 characters from description for mapping" + } $$::jsonb, + 1 assign new key/values to the results of the regular expression, and then back to the underlying row it came from