Guest User

Untitled

a guest
Feb 14th, 2019
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.45 KB | None | 0 0
  1. /*
  2. Table (named=> 'event_head') has one column (named=> 'data_dumb') as json which contains below json object.
  3. We want to read data from that JSON.
  4. ==================== EXAMPLE JSON Object ====================
  5.  
  6. {
  7. "timestamp": "2018-09-27T05:57:25.010Z",
  8. "source": "[email protected]",
  9. "sourceArn": "arn:aws:ses:eu-west-1:056345409346:identity/example.com",
  10. "sendingAccountId": "067935456346",
  11. "messageId": "01020166456a7592-0d87ab1d-ada6-4c0d-833f-30b066779ac6-000000",
  12. "destination": [
  13. ],
  14. "headersTruncated": false,
  15. "headers": [
  16. {
  17. "name": "Content-Type",
  18. "value": "text/html"
  19. },
  20. {
  21. "name": "From",
  22. "value": "Example <[email protected]>"
  23. },
  24. {
  25. "name": "To",
  26. "value": "[email protected]"
  27. },
  28. {
  29. "name": "Subject",
  30. "value": "Payment Refund"
  31. },
  32. {
  33. "name": "Message-ID",
  34. "value": "<[email protected]>"
  35. },
  36. {
  37. "name": "Content-Transfer-Encoding",
  38. "value": "quoted-printable"
  39. },
  40. {
  41. "name": "Date",
  42. "value": "Thu, 27 Sep 2018 05:57:24 +0000"
  43. },
  44. {
  45. "name": "MIME-Version",
  46. "value": "1.0"
  47. }
  48. ],
  49. "commonHeaders": {
  50. "from": [
  51. "Example <[email protected]>"
  52. ],
  53. "date": "Thu, 27 Sep 2018 05:57:24 +0000",
  54. "to": [
  55. ],
  56. "messageId": "01020166199a7592-0d87ab1d-ada6-4c0d-833f-30b013579ac6-000000",
  57. "subject": "Payment Refund"
  58. },
  59. "tags": {
  60. "ses:operation": [
  61. "SendRawEmail"
  62. ],
  63. "ses:configuration-set": [
  64. "Email-Stat-Config-Set"
  65. ],
  66. "ses:source-ip": [
  67. "34.006.155.219"
  68. ],
  69. "ses:from-domain": [
  70. "b2x.com"
  71. ],
  72. "ses:caller-identity": [
  73. "email-stat"
  74. ]
  75. },
  76. "eventType": "Send",
  77. "time": "2018-09-27T05:57:25.010Z",
  78. "send": {
  79.  
  80. }
  81. }
  82.  
  83. */
  84.  
  85.  
  86. SELECT e.value, d.value, eh.*
  87. FROM event_head eh
  88. JOIN json_array_elements((data_dump->>'headers')::json) e ON TRUE
  89. JOIN json_each_text(e::json) d ON TRUE
  90. WHERE e->>'name' = 'Subject';
  91.  
  92.  
  93.  
  94. /* ========================== OTHER ========================= */
  95.  
  96. SELECT mo.id, mo.model_code, mo.device_type--, e.value->>'model code' --, d->'model code'
  97. FROM mst_model mo,
  98. json_array_elements('[{"model code": "950A216200U4", "device type": "phone"}, {"model code": "95A12B0D0009", "device type": "phone"}]'::json) e
  99. --JOIN json_each_text(e::json) d ON TRUE
  100. WHERE mo.model_code = e.value->>'model code' AND mo.device_type = e.value->>'device type'
Add Comment
Please, Sign In to add comment