Я пишу в ядре .net и пытаюсь запустить хранимую процедуру из базы данных (Postgresql).
Я получаю сообщение об ошибке "Синтаксическая ошибка в конце ввода".
Строка подключения верна (обнаружена во время отладки). Проблема заключается в синтаксисе метода .FromSql ().
вот код:
List<ActivePackageForOpenBillingPeriod> activeUserPackagesForOpenBillingPeriod =null;
using(var conn = new NpgsqlConnection("Host=localhost;Port=xxx;Database=postgres;Username=xxx;Password=xxx;TrustServerCertificate=xxx;ApplicationName=xxx;"))
{
var s = "create function \"GetActiveUserPackagesForOpenBillingPeriod({0})\"";
activeUserPackagesForOpenBillingPeriod = context.ActivePackageForOpenBillingPeriods.FromSql(s,DateTime.Now).ToList();
}
Это хранимая процедура, которую я пытаюсь вызвать
create function "GetActiveUserPackagesForOpenBillingPeriod"(date
timestamp without time zone) returns TABLE("Amount" numeric, "Package"
character varying, "User" text,"Account" int, "AcceptanceActID" int,
"HasChangedPackage" boolean)
language plpgsql
as
$$
DECLARE
BEGIN
RETURN QUERY
SELECT
a."ID" AS "AccountId",
u."ID" AS "UserId",
up."PackageID",
up."TotalAmount",
CASE
WHEN count(DISTINCT tl."PackageID") IN (0,1) THEN false
ELSE true
END AS "HasChangedPackage"
FROM public."Accounts" as a
LEFT JOIN billing."TransactionHeaders" AS th ON th."AccountID" = a."ID"
INNER JOIN security."Users" AS u ON u."AccountID"= a."ID"
INNER JOIN billing."UserPackages" AS up ON up."UserID"=u."ID" AND COALESCE(th."Date", date) BETWEEN up."StartDate" AND COALESCE(up."EndDate", date)
LEFT JOIN billing."TransactionLines" AS tl ON th."Id" = tl."TransactionHeaderID"
WHERE th."AcceptanceActID" IS NULL AND a."StatusID"!=4 AND a."StatusID"!=3 AND up."StatusID"=1
GROUP BY a."ID", u."ID", up."PackageID", up."TotalAmount";
END;
$$;