Postgres nested if in case query

前端 未结 2 1686
忘掉有多难
忘掉有多难 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:47

    I don't know what you're trying to achieve with this function, but here's a working version.

    CREATE FUNCTION f_test(myvalue integer) RETURNS float AS $$
    BEGIN
        IF myvalue = 1 THEN
                IF 1=1 THEN
                        RETURN 0.30::FLOAT;
                ELSE
                        RETURN 0.50::FLOAT;
                END IF;
        ELSE
                RETURN 1.0::FLOAT;
        END IF;
    END;
    

    The function returns 0.3 if input value is 1, otherwise it'll return 1. Edit: Note that 0.5 is never returned by the function.

提交回复
热议问题