当前位置: 首页 > 面试题库 >

错误:查询没有返回FUNCTION的结果数据的目标数据bigint

秋煌
2023-03-14
问题内容

关于这个错误,有很多类似的问题,但是似乎没有一个问题可以解决我的问题。我在PostgreSql中创建了以下存储过程:

CREATE OR REPLACE FUNCTION "MySchema".UserAccountInsert(
    id             bigint,
    lang           varchar(3),
    nname          varchar(40),
    email          varchar(40),
    email_conf     boolean,
    status         smallint,
    status_update  bigint,
    creation       bigint,
    preferences    json)
    RETURNS bigint AS $BODY$
DECLARE
    rowc INTEGER;
    ret_id bigint;
BEGIN
    SELECT "ID" FROM "MySchema"."USER_ACCOUNT"
        WHERE "ID" = id OR "NAME" = nname OR "EMAIL" = email
        LIMIT 1;
    GET DIAGNOSTICS rowc = ROW_COUNT;
    IF ( rowc > 0 ) THEN
        ret_id = -1; /* Unsuccessful */
    ELSE
        IF ( id <= 0 ) THEN
            INSERT INTO "MySchema"."USER_ACCOUNT" ("LANG","NAME","EMAIL","EMAIL_CONF","STATUS","STATUS_UPDATE","CREATION","PREFERENCES")
            VALUES (lang,nname,email,email_conf,status,status_update,creation,preferences) RETURNING "ID" INTO ret_id;
        ELSE
            INSERT INTO "MySchema"."USER_ACCOUNT" ("ID", "LANG","NAME","EMAIL","EMAIL_CONF","STATUS","STATUS_UPDATE","CREATION","PREFERENCES")
            VALUES (id, lang,nname,email,email_conf,status,status_update,creation,preferences);
            ret_id = id;
        END IF;
    END IF;
    RETURN ret_id;
END; $BODY$
LANGUAGE plpgsql;

我试图用以下命令从pgAdmin III调用它:

SELECT "MySchema".UserAccountInsert(
    1000::bigint,
    'ENG'::varchar(3),
    'name1000'::varchar(40),
    'email1000'::varchar(40),
    'f'::boolean,
    1::smallint,
    1391878008121::bigint,
    1391878008121::bigint,
    '{}'::json) as ret_id;

但我收到以下错误消息:

ERROR:  query has no destination for result data
HINT:  If you want to discard the results of a SELECT, use PERFORM instead.
CONTEXT:  PL/pgSQL function "MySchema".useraccountinsert(bigint,character varying,character varying,character varying,boolean,smallint,bigint,bigint,json) line 6 at SQL statement

我应该如何调用我的函数?


问题答案:

跟随a_horse_with_no_name的评论,我对我的函数进行了如下修改

SELECT COUNT(*) INTO rowc FROM "MySchema"."USER_ACCOUNT"
    WHERE "ID" = id OR "NAME" = nname OR "EMAIL" = email
    LIMIT 1;
/* GET DIAGNOSTICS rowc = ROW_COUNT; */

而且有效!



 类似资料: