if column exists

Dear all,

I have to check a table if a column exists.
If yes (column is already existing): column values should be set to null
if no(column is not existing): column should be added.

in pseudo code:
if exists (column"test") then
all column(“test”)=null
else
add column(test)

In forum I found an node if column exists from column, but I can’t find it.

Is there a smart way to realize?

Thanks for help!

BR,

Heinz

Hi @Heinz

I have an “If Column Exists” component on the hub which maybe you’ve seen on the forum?

Just type in the column name you want to test and use it like a regular If node

(edit: corrected the images to note use of toNull() to create missing values.

3 Likes

Hi Heinz,

There is a „extract table spec“ node. It delivers the column names. Based on this you can add a row filter and a construct a „if-else“ loop

3 Likes

Yes, internally my above component does uses “extract table spec”.

There is also this clever alternative demo workflow from @s.roughley which uses the Vernalis nodes to solve this problem, so that’s another option too :wink:

It featured on the following forum thread

4 Likes

@Heinz using code there is also this solution

1 Like

That is the node I had in mind.
But I can’t find it searching in the nodes… I am using latest Knime with all updates.
When tyring to insert the node using drag and drop from your workflow I got the message:

ERROR CreateMetaNodeTemplateCommand Metanode loading failed with CoreException: The entity is not backed by an input stream, entity class is : java.io.InputStream

Any hint?

Thx for help!

BR,

Heinz