I try to declare simple function in postgres but I cannot make it work. It looks like this:
CREATE OR REPLACE FUNCTION test2(rok int, id int)
RETURNS int AS $$
BEGIN
select sum(data_zakonczenia-data_rozpoczecia) from historia where id_eksponatu = $2 AND data_rozpoczecia>DATE(to_char($1,'9999') || '-01-01') AND data_zakonczenia<DATE(to_char($1+1,'9999') || '-01-01');
END;
$$ LANGUAGE 'plpgsql';
I get following error
ERROR: query has no destination for result data
PODPOWIEDŹ: If you want to discard the results of a SELECT, use PERFORM instead.
KONTEKST: PL/pgSQL function "test2" line 2 at SQL statement
I am not sure how to make it work.