2018-03-02 01:01:46 -05:00
|
|
|
delete from tps.trans where srce = 'DMAPI';
|
|
|
|
|
|
|
|
----------------------set definition-----------------
|
|
|
|
SELECT
|
|
|
|
jsonb_pretty(r.x)
|
|
|
|
FROM
|
|
|
|
tps.srce_set(
|
|
|
|
$$
|
2018-05-25 13:44:37 -04:00
|
|
|
{
|
|
|
|
"name": "DMAPI",
|
|
|
|
"type": "csv",
|
|
|
|
"schemas": {
|
|
|
|
"default": [
|
|
|
|
{
|
|
|
|
"path": "{doc,origin_addresses,0}",
|
|
|
|
"type": "text",
|
|
|
|
"column_name": "origin_address"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"path": "{doc,destination_addresses,0}",
|
|
|
|
"type": "text",
|
|
|
|
"column_name": "destination_address"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"path": "{doc,rows,0,elements,0,distance,value}",
|
|
|
|
"type": "numeric",
|
|
|
|
"column_name": "distince"
|
|
|
|
},
|
2018-03-02 01:01:46 -05:00
|
|
|
{
|
2018-05-25 13:44:37 -04:00
|
|
|
"path": "{doc,rows,0,elements,0,duration,value}",
|
|
|
|
"type": "numeric",
|
|
|
|
"column_name": "duration"
|
2018-03-02 01:01:46 -05:00
|
|
|
}
|
|
|
|
],
|
2018-05-25 13:44:37 -04:00
|
|
|
"constraint": [
|
|
|
|
"{doc}"
|
|
|
|
]
|
2018-03-02 01:01:46 -05:00
|
|
|
}
|
2018-05-25 13:44:37 -04:00
|
|
|
}
|
2018-03-02 01:01:46 -05:00
|
|
|
$$
|
|
|
|
) r(x);
|
|
|
|
--------------------------build a csv file---------------------
|
|
|
|
|
|
|
|
copy
|
|
|
|
(
|
|
|
|
select
|
|
|
|
$$
|
|
|
|
{
|
2018-05-21 00:02:08 -04:00
|
|
|
"id": 1,
|
|
|
|
"doc": {
|
|
|
|
"rows": [
|
2018-03-02 01:01:46 -05:00
|
|
|
{
|
2018-05-21 00:02:08 -04:00
|
|
|
"elements": [
|
|
|
|
{
|
|
|
|
"status": "OK",
|
|
|
|
"distance": {
|
|
|
|
"text": "225 mi",
|
|
|
|
"value": 361940
|
|
|
|
},
|
|
|
|
"duration": {
|
|
|
|
"text": "3 hours 50 mins",
|
|
|
|
"value": 13812
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]
|
2018-03-02 01:01:46 -05:00
|
|
|
}
|
2018-05-21 00:02:08 -04:00
|
|
|
],
|
|
|
|
"status": "OK",
|
|
|
|
"origin_addresses": [
|
|
|
|
"Washington, DC, USA"
|
|
|
|
],
|
|
|
|
"destination_addresses": [
|
|
|
|
"New York, NY, USA"
|
|
|
|
]
|
|
|
|
}
|
2018-03-02 01:01:46 -05:00
|
|
|
}
|
|
|
|
$$::JSONB DOC
|
|
|
|
)
|
|
|
|
to 'C:\users\fleet\downloads\testj.csv' with (FORMAT CSV, QUOTE '"', HEADER true);
|
|
|
|
|
|
|
|
---------------------------------insert rows----------------------------------------
|
|
|
|
|
|
|
|
SELECT
|
|
|
|
*
|
|
|
|
FROM
|
|
|
|
tps.srce_import('C:\users\fleet\downloads\testj.csv','DMAPI') x(message);
|
|
|
|
|
|
|
|
|
|
|
|
select id, srce, jsonb_pretty(rec) from tps.trans where srce = 'DMAPI';
|