alexandrainst / node-red-contrib-postgresql

Node-RED node for PostgreSQL, supporting parameters, split, back-pressure
https://flows.nodered.org/node/node-red-contrib-postgresql
Apache License 2.0
32 stars 13 forks source link

no msg.complete or msg.count when using sequence #11

Closed nileio closed 2 years ago

nileio commented 2 years ago

thanks for the node. I dont get msg.count on any message , or msg.complete when using the split function. I also dont get rowCount or Command

Not sure why?

I get rowCount and Command if I don't use the split function

Alkarex commented 2 years ago

@nileio Please show your flow. Remember that when using split, you must send a msg.tick to the node to receive the next messages.

When using split, the node is using a PostgreSQL cursor and the available metadata is a bit different.

Messages will contain something like:

{
    "payload": [{
            ....,
        }
    ],
    "pgsql": {
        "command": null,
        "rowCount": null
    },
    "parts": {
        "id": 0.6229532880636226,
        "type": "array",
        "index": 9
    }
}

And the last message will contain something like:

{
    ...,
    "pgsql": {
        "command": "SELECT",
        "rowCount": 0
    },
    "parts": {
        "id": 0.6229532880636226,
        "type": "array",
        "index": 10,
        "count": 11
    },
    "complete": true
}

Please note that in that case, rowCount refers to the number of rows modified in database (e.g. by UPDATE or INSERT), not the number of rows returned.

Alkarex commented 2 years ago

See also https://node-postgres.com/api/result#resultrowcount-int

nileio commented 2 years ago

hi @Alkarex thanks for the information. I guess I had different expectations and so the confusion. I thought that rowCount will always have the total number of records regardless of whether or not the split function is used. I also thought that "complete": false will be there for every message emitted when using the split function except for the last one.

What you described is the actual behavior I am getting so looks like it is by design. I have workarounds now to work with that design. However, I would suggest to consider my suggestions as enhancements.

One more thing I could not find information about is msg.tick . The node documentation has something about provider and consumer so removing the need to send msg.tick - do you have an example of a flow using this feature ?