postgresql - Postgres - ERROR: syntax error at or near "IF" -


i have function , need different select based on inputid. have added condition below.

.... begin if(iv_binrocess = 1 , isnull(iv_binno,'') != '') ...//some process here  end if; ... end 

when run function, got error "

error: syntax error @ or near "if" referred many sites , tutorials, nothing helped me.

can me fix issue?

thanks

wag, since deleted of important information: you're trying create function pl/pgsql body, declaring sql.

craig=> create function test() returns void language sql  $$ begin if true perform 1; end if; end; $$ ; error:  syntax error @ or near "if" line 1: ...tion test() returns void language sql $$ begin if true th... 

declare pl/pgsql functions language plpgsql.

if instead want use sql function, use case expression instead of if.

create function test2() returns integer language sql  $$ select case when true 1 else 0 end; $$; 

(note, haven't bothered format these readably. don't write functions in 1 line in real code.)


Comments

Popular posts from this blog

python - Selenium remoteWebDriver (& SauceLabs) Firefox moseMoveTo action exception -

html - How to custom Bootstrap grid height? -

transpose - Maple isnt executing function but prints function term -