Need IF ELSE functionality workaround

Navin_CNavin_C Vertica Customer
Is there any way of using a IF ELSE statement in Vertica. Any workaround on this. I have a scenario where I need to count the (select query value) store it in a variable and if the variable value is greater then 1 I need to execute a bunch of SQL statements. Any help appreciated.

Comments

  • Hi, I believe that you are looking for the CASE expression. https://my.vertica.com/docs/6.1.x/HTML/index.htm#3056.htm Please let me know if this helps. Eugenia
  • Navin_CNavin_C Vertica Customer
    Hello Eugenia, I already know the case expression, but I don't think this can be handeld by the case expression as my scenario need to execute a bunch of sql statement depending on the count of a select query if it is greater then or equal to 1.
  • See this working example : select case when memory_inuse_kb =0 then (select 1 from dual) when memory_inuse_kb >0 then (select 2 from dual) end from resource_pool_status
  • It might help to collect the 'bunch of sql' into an sql function: https://my.vertica.com/docs/6.1.x/HTML/index.htm#15022.htm Then execute the function contingent on your predicate: select my_bunch_of_sql() where (select count(*) from t where something) >= 1; or, simpler and probably faster: select my_bunch_of_sql() where exists (select * from t where something);
  • Navin_CNavin_C Vertica Customer
    Hello Greorge, Can we use the SQL statments like insert, update and delete in the return clause of the Functions. I don't think the functions are so flexible to make it that way. Can you please suggest.

Leave a Comment

BoldItalicStrikethroughOrdered listUnordered list
Emoji
Image
Align leftAlign centerAlign rightToggle HTML viewToggle full pageToggle lights
Drop image/file