0

I have written this function:

create function check_same_price() returns integer as $result$
declare
 result integer;
begin
 set res = (select *
  from (select count(distinct title), price_dvd_buy
  from dvd_to_buy
  group by price_dvd_buy) as dummy
  where count>1);
if (res==none) then result=0;
else result=1;
end if;
end;
$result$ language plpgsql;

the function returns 0 if there is the same price for same title, otherwise it returns 1. This check is done because I want the same price for the same film; I'm using phppgadmin to manage it. I receive this error:

SQL error:

ERROR:  error of sintax to or near "("
LINE 5:  set res = (select *

What's wrong, I don't know to fix it. Thanks!

1

1 Answer 1

1
create function check_same_price()
returns boolean as $$
begin
   return exists(select count(distinct title)
                    from dvd_to_buy
                   group by price_dvd_buy
                   having count(distinct title) > 1)
end;
$$ language plpgsql;
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.