I have one table in posgres and i have a number of items. I would then check if that item exists in the database if it is not existing not it should be added. How could this be done? By query and then an if formula?
= lookup item, if existing = stop
= lookup item, if no existing = add
I have tried a few different ones but not really got it to work.
I guess the problem you have is that the Postgres-Node does not output anything in case it does not find the item. So you have to set on the Postgres-Node under Node (not under Parameters!) the option “Always Output Data” to “true”. If you do not do that it will not output anything and the workflow will stop. Only with that option will it at least output an empty item and you can then check for it.
I created the following example workflow which assumes you have a table called “product” which has the properties: id, timestamp
Not sure what you want to do exactly but looks generally correct to me. Without knowing what the node “convertSubscribers” does actually output and the same what the input of the “Set” nodes does output it is impossible to say for sure what is going wrong. Additionally would also have to know what you expect the “Set” node to do.
In the convertSubribers do i make an array become repeating items. Then i use the postgres to check if the item already exists. If yes then it should update (true on if) and if not exist it should add. The set node i used to prepare the json that should to into postgres. I just copied the example you gave me. The problem i have is is that it only add the first item of the array and to not repeat for all of them.
Because of the way the Postgres node currently operates there is right now sadly no simple way to build such a workflow. At least not with my very limited postgres query building skills. For that reason did I have to use SplitInBatches Node.
Here an example workflow which creates n8n workflows directly in the database and so does something similar like you want to do: