Add column if doesn't exist

Hi,

Is there a way to add a column with a fixed value if doesn't exist?

Thanks

1 Like

look for the node 'constant value column'

As you need to check if the column exists, you must aply a workaround.

Extract the column header and transpose it into flow variables (Extract Column Header-> Table Row to Flow Variable) then use a Java Edit Variable to check the column names. Than generate with the JEV a FlowVariable saying both or bottom. This you can feed into a If Switch node. And generate with the Constant Value Column the column only for the top part. Don't forget to collect both branches from the if node with a End If node.

Cheers, Iris

2 Likes

Hi Iris … this is exactly the solution that I am looking for. I have no java experience so when you got into the Java part I got lost. Do you possibly have an example flow of this solution that I can tinker with to implement to sort out my problematic data?

Tx

tC/.

Hi @TigerCole

yes 5 years later there are better solutions for this :slight_smile:

I would now use the Table Validator for this.
You can in the dialog define what happens if certain columns are missing, and add them with Missing Values in case they are not there. The Missing Value can than add you a fixed value into these missing values.

If you have a second reference table, you can also use the Table Validator (Reference) Than you do not have to take care of configuring the node per column.

9 Likes

Thanks Iris … this is awesome!!

tC/.

2 Likes

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.