在MS T-sql 里这样的表达,在pg 里怎么写?
create proc insertfav(@userid int ,@topicid int)
as
if not exists(select id from favor where userid=@userid and topicid=@topicid)
begin
insert into favor(userid,topicid) values(@userid,@topicid)
if (select count(*) from favor where userid=@userid)>=30
delete from favor where userid=@userid and id not in(select top 30 id from favor where userid=@userid order by id desc )
end