Skip to content

Instantly share code, notes, and snippets.

@kovid-rathee
Created February 23, 2019 21:12
Show Gist options
  • Save kovid-rathee/fb036e69d65a981ec6372ddb57ca3c3b to your computer and use it in GitHub Desktop.
Save kovid-rathee/fb036e69d65a981ec6372ddb57ca3c3b to your computer and use it in GitHub Desktop.
Convert JSON to a Record Type in PostgreSQL
select * from json_to_record('{
"id": "pay_29QQoUBi66xm2f",
"entity": "payment",
"amount": 5000,
"currency": "INR",
"status": "captured",
"order_id": null,
"invoice_id": null,
"international": false,
"method": "wallet",
"amount_refunded": 0,
"refund_status": null,
"captured": true,
"description": "Purchase Description",
"card_id": null,
"bank": null,
"wallet": "freecharge",
"vpa": null,
"email": "a@b.com",
"contact": "91xxxxxxxx",
"notes": {
"merchant_order_id": "order id"
},
"fee": 1438,
"tax": 188,
"error_code": null,
"error_description": null,
"created_at": 1400826750
}') as t (id varchar, entity varchar, amount int, currency varchar,
status varchar, order_id varchar, invoice_id varchar,
international boolean, method varchar, amount_refunded int,
refund_status varchar, captured boolean, description varchar,
card_id varchar, bank varchar, wallet varchar, vpa varchar,
email varchar, contact varchar, notes json, fee int, tax int,
error_core varchar, error_description varchar, created_at int);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment