簡體   English   中英

我想在Postgresql數據庫的sql中添加此函數

[英]I want to add this function in sql in a Postgresql Database

我寫了這個功能:

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;

如果同一標題的價格相同,則該函數返回0,否則返回1。執行此檢查的原因是我希望同一部電影的價格相同; 我正在使用phppgadmin進行管理。 我收到此錯誤:

SQL error:

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

怎么了,我不知道要解決。 謝謝!

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;

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM