Got it to work...Using the template node I had to make the sql query, then use the function query to build the full message that has to get passed to the postgres node. Thanks all for your help.