I prefer creating e.g. SQL statements or REST statements ahead of time in full text within Knime. This enables me to copy the statements out of Knime and e.g. use them directly with a different SQL Tool.
But, i came to dislike String Manipulations Join function, be it in the String Manipulation node, Column Expression Node, or the worst in the new Expression node.
These are fine if you need to use 1-2 columns or flow vars and have shorter statements.
But longer statements are a pita.
Essentially, writing something like this in Knimes Expression Node:
join(
"",
"USE ", $(database_name)$, ";
IF NOT EXIST (
SELECT column_name
FROM information_schema.columns
WHERE
schema_name = '", $(schema_name)$, "' AND
tablen_name = '", $(table_name)$, "' AND
column_name = 'HARDCODED'
)
ALTER TABLE '", $(schema_name)$, "'.'", $(table_name)$, "'
ADD COLUMN 'HARDCODED' NVARCHAR(48)
NOT NULL CONSTRAINT 'constr_", $(schema_name)$, "_", (table_name)$, "_HARDCODED' DEFAULT 'HARDCODED';"
)
feels just bad because not only do you have to pay attention to the quoting symbols of the dialect you are talking to ( [] vs "" vs '' ) but you have the additional quotes, commas and $$, $[ or $( from Knime in your view (depending on the node you use). Personally is very annoying.
I used to run something like this in the past where instead I wrote my statement in one go and added placeholders to replace
ALTER TABLE {} ADD COLUMN {} NVARCHAR(48) NOT NULL CONSTRAINT 'constr_{}_{}_HARDCODED' DEFAULT 'HARDCODED'
or
ALTER TABLE {1} ADD COLUMN {2} NVARCHAR(48) NOT NULL CONSTRAINT 'constr_{3}_{4}_HARDCODED' DEFAULT 'HARDCODED'
and then replaced it in another step to add all the values in the right places. Hence, you only have the " at the start and end once.
This isnt too far off from classical printf() and alike but it feels a lot smoother to produce for me starting from a table like
| database_name | schema_name | table_name |
|---|---|---|
| db1 | schema1 | table1 |
| db1 | schema1 | table2 |
| db2 | schema1 | table1 |
Anyone else facing or tackling these issues in one way or another which could less annoying?






