Postgres nested if in case query

前端 未结 2 1695
忘掉有多难
忘掉有多难 2021-02-15 18:17

Could you tell my why the following isnt working in postgres sql?:

See updated code below

UPDATE:

I expect the query to return \"0.30\"

2条回答
  •  长发绾君心
    2021-02-15 18:44

    There is no IF expr THEN result ELSE result END syntax for normal SQL queries in Postgres. As there is neither an IF() function as in MySQL, you have to use CASE:

    select (
      case (select '1')
      when '1' then
        case when 1=1 then 0.30::float else 0.50::float end
      else
         1.00::float
      end
    );
    

提交回复
热议问题