Guest User

Untitled

a guest
Feb 14th, 2019
144
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": "adc@example.com",
  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. "xyz@example.com"
  14. ],
  15. "headersTruncated": false,
  16. "headers": [
  17. {
  18. "name": "Content-Type",
  19. "value": "text/html"
  20. },
  21. {
  22. "name": "From",
  23. "value": "Example <adc@example.com>"
  24. },
  25. {
  26. "name": "To",
  27. "value": "xyz@example.com"
  28. },
  29. {
  30. "name": "Subject",
  31. "value": "Payment Refund"
  32. },
  33. {
  34. "name": "Message-ID",
  35. "value": "<89fa9068-4ac5-b46f-7091-96b278d35ef1@b2x.com>"
  36. },
  37. {
  38. "name": "Content-Transfer-Encoding",
  39. "value": "quoted-printable"
  40. },
  41. {
  42. "name": "Date",
  43. "value": "Thu, 27 Sep 2018 05:57:24 +0000"
  44. },
  45. {
  46. "name": "MIME-Version",
  47. "value": "1.0"
  48. }
  49. ],
  50. "commonHeaders": {
  51. "from": [
  52. "Example <adc@example.com>"
  53. ],
  54. "date": "Thu, 27 Sep 2018 05:57:24 +0000",
  55. "to": [
  56. "xyz@example.com"
  57. ],
  58. "messageId": "01020166199a7592-0d87ab1d-ada6-4c0d-833f-30b013579ac6-000000",
  59. "subject": "Payment Refund"
  60. },
  61. "tags": {
  62. "ses:operation": [
  63. "SendRawEmail"
  64. ],
  65. "ses:configuration-set": [
  66. "Email-Stat-Config-Set"
  67. ],
  68. "ses:source-ip": [
  69. "34.006.155.219"
  70. ],
  71. "ses:from-domain": [
  72. "b2x.com"
  73. ],
  74. "ses:caller-identity": [
  75. "email-stat"
  76. ]
  77. },
  78. "eventType": "Send",
  79. "time": "2018-09-27T05:57:25.010Z",
  80. "send": {
  81.  
  82. }
  83. }
  84.  
  85. */
  86.  
  87.  
  88. SELECT e.value, d.value, eh.*
  89. FROM event_head eh
  90. JOIN json_array_elements((data_dump->>'headers')::json) e ON TRUE
  91. JOIN json_each_text(e::json) d ON TRUE
  92. WHERE e->>'name' = 'Subject';
  93.  
  94.  
  95.  
  96. /* ========================== OTHER ========================= */
  97.  
  98. SELECT mo.id, mo.model_code, mo.device_type--, e.value->>'model code' --, d->'model code'
  99. FROM mst_model mo,
  100. json_array_elements('[{"model code": "950A216200U4", "device type": "phone"}, {"model code": "95A12B0D0009", "device type": "phone"}]'::json) e
  101. --JOIN json_each_text(e::json) d ON TRUE
  102. WHERE mo.model_code = e.value->>'model code' AND mo.device_type = e.value->>'device type'
Add Comment
Please, Sign In to add comment