I have function in PostgreSQL, when I want to return the results I got error :
ERROR: query has no destination for result data
HINT: If you want to discard the results of a SELECT, use PERFORM instead.
Here is summary my function ( it's too long to copy/paste all of code here)
CREATE OR REPLACE FUNCTION "schema"."test"(IN Id int8,)
RETURNS TABLE("Id" uuid, "SiteId" uuid, "Domain" varchar,
"JumpCost" numeric, "CPMCost" numeric, "PaymentModel" int8, "ComputedEpm" numeric,
"ClickedCampaignId" int8, "MainRubricId" int8, "ShowSlider" bool,
"ShowGoods" bool, "ShowTeaser" bool, "BidLimitCoeff" numeric,
"RtbActiveSiteStatByBannerId" int8, "ShowType" int8, "MinAge" int8) AS
$BODY$
DECLARE
rtbCampaignEpmCoeff NUMERIC(18,6);
maxRubricShows int;
showsRubricAddedPerClick int;
siteLossLimitPerRubric NUMERIC(18,6);
rtbMinRubricVisitsToShow int;
showAdsToUsersWithoutInterests boolean;
BEGIN
......
DO
$do$
......
$do$;
PERFORM "Id", "SiteId", "Domain", "JumpCost", "CPMCost", "PaymentModel",
5 as ComputedEpm, "ClickedCampaignId", "MainRubricId", "ShowSlider",
"ShowGoods", "ShowTeaser", "BidLimitCoeff", "RtbActiveSiteStatByBannerId",
"ShowType", "MinAge"
FROM mytable
ORDER BY "FromClick" DESC, "Similarity" DESC, "rn", random()
LIMIT 1;
END;
$BODY$
LANGUAGE plpgsql
COST 100
CALLED ON NULL INPUT
SECURITY INVOKER
VOLATILE;
As you see I used "PERFORM" to return results, but failed with error I explained.
Also, I used "Return query .. " and got same error.
"mytable" is temp table that I created in function.
How I can return this result?
return query. See the manual for details, it's all explained there: postgresql.org/docs/current/static/… Unrelated, but: you should really avoid those dreaded quoted identifiers, they are much more trouble then they are worth it.DOanonymous block of code when you are already inside a function?p_idandp_siteid. And by the way, avoid upper case and mixed case names wherever possible.