关于这个错误有很多类似的问题,但似乎没有一个回答我的情况。我在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
我该如何调用我的功能?
答案 0 :(得分:0)
在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; */
它有效!