sql - Is there a function in MonetDB that is equivalent to IF? -


i need in monetdb:

select   if(value > 0, value, -1) selected_value   table 

in mysql, means 'return value if value > 0, otherwise return -1.' there equivalent function in monetdb?

and not looking case statement. know exists in both monetdb , other sql languages. know of example gave.

thank you

as far know there isn't equivalent function in monetdb.

the if() function part of mysql extensions standard sql, extension in not part of monet builtin function

like many other sql database in monetdb not available ´if()´ function because isn't part of standard sql language.

for other evidence see this question , try query in standard parser.

i'm aware not looking case statement, howsoever , according sql in nutshell: ansi sql2003 provides function named case] can used create if-then flow-control logic within queries or update statements.

the case function provides if-then-else functionality within select or update statement. evaluates list of conditions , returns 1 value out of several possible values.

case has 2 usages: simple , searched. simple case expressions compares 1 value, input_value, list of other values , return result associated first matching value. searched case expressions allow analysis of several logical conditions , return result associated first 1 true.

monetdb supported features includes:

  • f261: case expression
  • f261-01: simple case
  • f261-02: searched case

therefore , in opinion, best chance code ´boolean searched operation´ is:

select    case when value > 0 value else -1 end selected_value   table; 

furthermore the monetdb dcumentation flowcontrol reports allows both ´case when´ , ´if else´and sql standard allows create sql functions , monetdb has support.

i think ,but don't encourage , not tested, might define own function; that:

 create function my_conv(value int)  returns int  begin     if (value > 0)         return value         else return -1;     end if;  end; 

hence

 select my_conv(value) table; 

even more complicated try code userdefinedfunction


Comments