Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

storing multi-rows data in PostgreSQL DB from a single message #3146

Open
ngjaying opened this issue Aug 28, 2024 Discussed in #3141 · 0 comments
Open

storing multi-rows data in PostgreSQL DB from a single message #3146

ngjaying opened this issue Aug 28, 2024 Discussed in #3141 · 0 comments
Labels
kind/feature New feature or request
Milestone

Comments

@ngjaying
Copy link
Collaborator

Discussed in #3141

Originally posted by robodevchampion August 23, 2024
I have data coming like below after executing SQL

{'device_name': 'sensor2', 'ts': '1724231947811', 'values': {'combine': '41:107', 'humidity': 41, 'temperature': '30'}}

Added an action for insertion data in DB, I have enabled send single as False

Below is the data template I am using

[
  {{- $firstMsg := true -}}
  {{- range $i, $msg := . -}}
    {{- $firstKey := true -}}
    {{- range $key, $value := $msg.values -}}
      {{- if not $firstKey -}},{{- end -}}
      {{- $firstKey = false -}}
      {
        "deviceid": "{{$msg.device_name}}",
        "ts": "{{$msg.ts}}",
        "key_name": "{{$key}}",
        "value": "{{$value}}"
      }
    {{- end -}}
    {{- if not $firstMsg -}},{{- end -}}
    {{- $firstMsg = false -}}
  {{- end -}}
]

Below is the error I got:

fail to decode data [{
        "deviceid": "sensor1",
        "ts": "1724231947811",
        "key_name": "combine",
        "value": "40:107"
      },{
        "deviceid": "sensor1",
        "ts": "1724231947811",
        "key_name": "humidity",
        "value": "40"
      },{
        "deviceid": "sensor1",
        "ts": "1724231947811",
        "key_name": "temperature",
        "value": "200"
      }]
 after applying dataTemplate for error json: cannot unmarshal array into Go value of type map[string]interface {}

Can you help me what I am missing, above data format is desired.

Thanks

@ngjaying ngjaying added the kind/feature New feature or request label Aug 28, 2024
@ngjaying ngjaying added this to the 2.0.0 milestone Aug 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/feature New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant