Sql server 存储过程SQL Server迁移到PostgreSQL
我正在将存储过程从SQL Server迁移到PostgreSQL。我已将存储过程转换为Postgres函数 SQL Server存储过程:Sql server 存储过程SQL Server迁移到PostgreSQL,sql-server,postgresql,stored-procedures,plpgsql,Sql Server,Postgresql,Stored Procedures,Plpgsql,我正在将存储过程从SQL Server迁移到PostgreSQL。我已将存储过程转换为Postgres函数 SQL Server存储过程: CREATE PROCEDURE AddFullSig @CandID int, @FullSig binary(16) AS if not exists (select pub_id from local_lib where cand_id = @CandID and
CREATE PROCEDURE AddFullSig @CandID int, @FullSig binary(16)
AS
if not exists (select pub_id
from local_lib
where cand_id = @CandID and Full_sig = @FullSig)
insert into local_lib
values(@CandID, 1, @FullSig)
else
update local_lib
set dup_count = dup_count + 1
where cand_id = @CandID
and Full_sig = @FullSig
select pub_id
from local_lib
where cand_id = @CandID and Full_sig = @FullSig
RETURN
博士后功能:
create type addfullsig_return_type as(
pub_id int
);
create or replace function addfullsig( p_candid int, p_fullsig bytea)
returns addfullsig_return_type as $$
begin
if not exists(select pub_id from local_lib where cand_id = p_candid and full_sig = p_fullsig) then
insert into local_lib values(default, p_candid, 1, p_fullsig);
else
update local_lib set dup_count = dup_count + 1 where cand_id = p_candid and full_sig = p_fullsig;
end if;
select pub_id from local_lib where
cand_id = p_candid and full_sig = p_fullsig;
end;
$$ language plpgsql;
当我尝试在pgadmin中使用以下工具测试此功能时:
select * from addfullsig(3,1010111011111011);
我得到一个错误:
错误:函数addfullsig(整数,bigint)不存在
我不确定我到postgresql的转换是否正确,尤其是在将bytea用于二进制(16)而不是位(16)时。如有任何帮助或见解,将不胜感激 1和0的序列被解析为整数文本,并猜测其类型为
bigint
使用位字符串语法:
select * from addfullsig(3,B'1010111011111011');
更多信息请参见1和0的序列被解析为整数文本,并猜测其类型为
bigint
使用位字符串语法:
select * from addfullsig(3,B'1010111011111011');
更多信息请参见您的第二个参数是
bytea
而不是long
值。有关如何传递“blob”文本的详细信息,请参阅手册:使用insert on conflict
而不是if语句将更有效(更健壮)。第二个参数是bytea
而不是long
值。有关如何传递“blob”文本的详细信息,请参阅手册:使用insert on conflict
而不是if语句将更有效(更健壮)。