Transformers at the end of SQL Query - adding an additional column

I am attempting to write a transformer at the end of a SQL query that would append a new column to the data returned (in data)

I have created a rez array - which basically just has true or false in it depending on another column.

So I have the array - and the data - how do I put them together and return the result?

I am kind of new to javascript - but my SQL is pretty good.

1 Like

Hi @dbApostle,

Welcome to Retool!

You can definitely do this with JS. I'd need to see a sample of your data and the rezArray to be sure what you'd need to do. Do you need the rezArray at all if the extra column is just based on the data in other columns? If that's the case, you should be able to do it directly in SQL.

    WHEN col1 = 1 AND col2 = 1 THEN 1
    WHEN col1 = 1 AND col2 = 2 THEN 2
    WHEN col1 = 2 AND col2 = 1 THEN 3
    ELSE 4
  END AS extra_col

If it needs to look something up from the rezArray and absolutely needs to be done with a transformer, share some sample data and I can show you a sample of how to do it with JS.

1 Like