我有功能的腳本,我從SQL Server到Postgres的,現在轉換當我跑我得到一個錯誤如何從Postgres函數返回表格作爲表格?
ERROR: structure of query does not match function result type
我的函數獲得3個參數(siteid bigint, datefrom timestamp, dateto timestamp
),並應返回我列入表中的功能在代碼中。我使用了「返回查詢」。
我執行我的功能是這樣的:
getrtbactivesiteplaces(1475, '2016-02-01', '2016-08-01')
如何我能得到這個結果從我的功能表?
這是我的功能截圖
{
CREATE OR REPLACE FUNCTION "whis2011"."getrtbactivesiteplaces"(IN siteid int8, IN datefrom timestamp, IN dateto timestamp) RETURNS SETOF "varchar"
AS $BODY$
DECLARE
siteid BIGINT;
datefrom timestamp without time zone;
dateto timestamp without time zone;
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
/* SQLWays Notice: SET TRANSACTION ISOLATION LEVEL READ COMMITTED must be called before procedure call */
-- SET TRANSACTION ISOLATION LEVEL READ COMMITTED
-- Insert statements for procedure here
RETURN QUERY SELECT pl."Id",
pl."RtbActiveSiteId",
pl."AdPlaceId",
pl."AdPosition",
pl."Ctr",
pl."State",
pl."BidPrice",
pl."MinBidFloor",
pl."MinBidFloorCurrency",
pl."AverageCpm",
pl."AverageClickCost",
coalesce(SUM(ss."BidsCount"),0) AS BidsCount,
coalesce(SUM(ss."ShowsCount"),0) AS ShowsCount,
coalesce(SUM(ss."RealShowsCount"),0) AS RealShowsCount,
coalesce(SUM(ss."ClicksCount"),0) AS ClicksCount,
coalesce(SUM(ss."ClickLayerClicksCount"),0) as ClickLayerClicksCount,
coalesce(SUM(ss."ShowsCost"),0::money) AS ShowsCost,
coalesce(SUM(ss."ClicksCost"),0::money) AS ClicksCost,
coalesce(SUM(ss."BidsCost"),0::money) AS BidsCost,
coalesce(SUM(ss."SliderMovesCount"),0) AS SliderMovesCount
FROM "whis2011"."RtbActiveSitePlaces" pl
LEFT OUTER JOIN "whis2011"."RtbActiveSitePlaceStatistics" ss ON ss."RtbActiveSitePlaceId" = pl."Id"
WHERE ss."Date" >= datefrom AND ss."Date" < dateto AND pl."RtbActiveSiteId" = siteid
GROUP BY pl."Id", pl."RtbActiveSiteId", pl."AdPlaceId", pl."AdPosition", pl."Ctr", pl."State", pl."BidPrice",
pl."MinBidFloor", pl."MinBidFloorCurrency", pl."AverageCpm", pl."AverageClickCost";
END;
$BODY$
LANGUAGE plpgsql
COST 100
CALLED ON NULL INPUT
SECURITY INVOKER
VOLATILE;
}
如果你的問題是什麼圖形,通過各種手段包括屏幕截圖。如果是代碼,請不要向我們展示代碼圖片。在這裏發佈實際的代碼。 – Gerrat
如果函數返回一個表,則需要使用'select * from getrtbactivesiteplaces(1475,'2016-02-01','2016-08-01')' –
http://meta.stackoverflow.com/questions/ 285551/why-may-i-not-upload-images-code-on-so-when-asking-question/285557#285557 –