Using a Position Function in a Case Function - PostgreSQL -


i'm new sql , postgres, isn't hard figure out of you.

i'm trying use position function within case statement, keep getting error "error: syntax error @ or near ""project"". line 2: case when position('(' in "project") >0 then".

i've used position function before , worked fine, i'm confused problem here. i've tried table name, such "xyztable.project" , "project" - both without quotation marks.

here entire statement:

select "project", case when postion('(' in "project") >0     substring("project",position('(' in "project")+1,position(')' in "project")-2) case when postion('('in "project") null     "project" end "2015budget"; 

as haven't gotten past second line of statement, if sees prevent statement running correctly, please feel free point out.

new statement:

select "project", case    when position('(' in "project") >0     substring("project",position('(' in "project")+1,position(')' in "project")-2)   when position('('in "project") null     "project" end "2015budget"; 

thank help!!

the error due simple typo - postion instead of position.

you more comprehensible error message in situations (e.g. "function postion(text,text) not exist"). however, use of function-specific keywords argument separators (as mandated sql standard) makes case more difficult parser cope with.

after fixing this, you'll run error. note general form of multi-branch case expression is:

case   when <condition1> <value1>   when <condition2> <value2>   ... end 

Comments

Popular posts from this blog

c# - How Configure Devart dotConnect for SQLite Code First? -

java - Copying object fields -

c++ - Clear the memory after returning a vector in a function -