There are many similar questions on SO about this error, but none seem to answer my case. I have created the following stored procedure in 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;
and I am trying to call it from pgAdmin III with:
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;
but I am getting the following error message:
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
How should I call my function?