PostgreSQL: Query has no destination for result data

前端 未结 4 1924
太阳男子
太阳男子 2020-12-09 08:50

I am trying to fetch data from remote db by using dblink through function but getting an error \"query has no destination for result data\". I am using plpgsql language to d

相关标签:
4条回答
  • Reason for the error you're getting is because there is no return in between your BEGIN and END for example:

        BEGIN
            update mytable set lastcodeused = to_char(cast(lastcodeused as INTEGER)+1, 'FM999999999999999999') where 
            classid = classIdVar and appid= appIdInt 
            RETURNING concat(pageUniqueCode,lastcodeused) as pageUniqueCode
            into taskcode;
            return taskcode;
        END;
    
    0 讨论(0)
  • 2020-12-09 09:30

    Answer from SL2 was right, but you can write it in the short way:

    CREATE OR REPLACE FUNCTION fun() RETURNS text AS $$
    BEGIN
        --- ....
        RETURN(SELECT dblink_disconnect());
    END
    $$ LANGUAGE plpgsql;
    
    0 讨论(0)
  • 2020-12-09 09:33

    The stored procedure won't just return the result of the last SELECT. You need to actually return the value:

    CREATE OR REPLACE FUNCTION fun() RETURNS text AS $$
    BEGIN
        --- ....
        RETURN(SELECT dblink_disconnect());
    END
    $$ LANGUAGE plpgsql;
    

    You're getting the error because Postgres expects the function to return something of type text, but your function doesn't return anything.

    0 讨论(0)
  • 2020-12-09 09:33

    Use a plain SQL function instead of PL/PgSQL, or use SELECT INTO and ordinary RETURN.

    0 讨论(0)
提交回复
热议问题