Всем привет, работаю в postgresql, в чем ошибка?
CREATE OR REPLACE FUNCTION ten(integer) RETURNS table(f1 text, f2 integer, f3 integer, f4 integer)
AS
'
select
case
when
types.id=1 then 'квартира'
when
types.id=2 then 'дом'
when
types.id=3 then 'ап-ты'
end, count(*), count(*)*100/newcolumn, sum(sale.cost_sale)
from types, objects, sale, (select count(*) as newcolumn from sale where extract(year from date_sale)=$1) newtable
where sale.id_object=
objects.idand objects.type=
types.idand extract(year from sale.date_sale)=$1
group by
types.id, newcolumn
'
LANGUAGE SQL;
select * from ten(2021);
Код ошибки:
ERROR: ОШИБКА: ошибка синтаксиса (примерное положение: "квартира")
LINE 6: when
types.id=1 then 'квартира'