Is there a way to set up an if/else statement with...
# ask-community
j
Is there a way to set up an if/else statement within a flow depending on if a SQL query errors out? For example,
if(select * from table) = error then (alter table add column) else somethingelse
?
k
Use the case task on this page this checks for a condition. If is evaluated during build time. You need something to evaluate during runtime
j
Just what I need, thank you
One other quick q @Kevin Kho - is there a way to quickly detect if there is a column already present in a destination table? Without querying information schema. I want to add a timestamp to ALL data in a SQL table but I'm only uploading 1 days worth at a time, and some tables might not already have the timestamp column in place
ex.
if (column last refresh exists) then (add refresh time) else (add column last refresh then add refresh time)
. I tried some IF EXISTS SQL but that didn't quite work
k
I dont think this is a simple operation in SQL. I think you need to query information tables but I can be wrong
j
so provided the information schema is BLANK/null (i.e. no column), what would I want in that "if" statement within Prefect itself?
if length(results)=0 (null?), then "do stuff"?
k
If there are no columns, I think so, but of course do this inside a task and use the
case
instead of
if