У меня ниже скрипт миграции.Я не знаю, почему это ошибка, если я запускаю только СОЗДАТЬ ИЛИ ЗАМЕНИТЬ ФУНКЦИЮ блокировать его работу ..
DO $$
BEGIN
IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "MigrationId" = '20190305152943_SupportLocationAndAsset') THEN
CREATE OR REPLACE FUNCTION build_hierarchey(location_id int default null::int, prefer_depth int default null::int)
RETURNS SETOF jsonb AS
$$
BEGIN
IF prefer_depth < 0 THEN
RETURN;
ELSE
prefer_depth := prefer_depth - 1;
RETURN QUERY
SELECT
CASE WHEN COUNT(x) > 0
THEN (((to_jsonb(t) || jsonb_build_object('Children', jsonb_agg(f.x))) - 'SearchVector') - 'ParentLocationId')
ELSE ((to_jsonb(t) - 'SearchVector') - 'ParentLocationId')
END
FROM "Locations" t
LEFT JOIN build_hierarchey(t."Id", prefer_depth) AS f(x) ON true
WHERE t."ParentLocationId" = location_id OR (location_id IS null AND t."ParentLocationId" IS null)
GROUP BY t."Id", t."Name";
END IF;
RETURN;
END;
$$ LANGUAGE plpgsql
END IF;
END $$;
Ошибка
ERROR: syntax error at or near "BEGIN"
LINE 8: BEGIN
^
SQL state: 42601
Character: 286