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
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
http://bianbian.sunshow.net/index.php/technology/52.html
不过现在又出现的新问题是我执行create function.......language plpgsql时
有错误提示,plpgsql 未安装要create language 来安装;
我create language plpgsql时又提示需要superuser,现在是不是我必须请求
服务器数据库管理员来给我权限或为我create laguage才行,我自己是不是没什么办法了?
对了,还有两个小问题,我已经结帐了,不知你能否看到,能的话也回答一下,
1,function 的参数,我知道可以用$1,$2这样的位置指示符来表示,但这样代码的可读性不好,
我也知道可以用别名,但由于别名前不加任何区分符,所以很容易跟表的列名看混,这个问题是不是没有好的办法?
2,如果function 返回值为空的话,调用的时候是不是也一定要放在表达式里来执行,我是select xxx(t1,t2)这样的,没有专门的 execute 语句吗 ?