错误类型强制转换Postgresql函数

时间:2018-04-21 18:35:47

标签: sql postgresql function types casting

您好我有这个错误

错误:psql:/Samsung/VisualCodeStudioWorkspace/1524335164735.pgsql:95:错误:函数altaplayer(字符变化,整数,整数,字符变化,字符变化)不存在 第1行:选择altaPlayer(varchar' Drazen Petrovic',52,80,varchar ...                ^ 提示:没有函数匹配给定的名称和参数类型。您可能需要添加显式类型转换。 psql结束。

我无法解决超过两天......我已经尝试过各种各样......

CREATE TYPE player AS (
    nom varchar(20),
    alçada integer,
    pes integer,
    posicio varchar(20),
    equip varchar(20)
);

CREATE TABLE player_list of player(
    primary key(nom)
);

CREATE TABLE team (
    jugador player
);

INSERT INTO team VALUES(row('Pepelu',190,90,'Base','Barça'));
INSERT INTO player_list VALUES('Asterix',50,30,'Base','Barça');
INSERT INTO player_list VALUES('Pepelui',100,90,'Alero','Barça');
INSERT INTO player_list VALUES('Manolo',10,50,'Base','Barça');
INSERT INTO player_list VALUES('Juan',50,30,'Base','Barça');
INSERT INTO player_list VALUES('Fernando Martin',50,30,'Pivot','Barça');
INSERT INTO player_list VALUES('Audie Norris',50,30,'Pivot','Barça');


create or replace function altaPlayer ( varchar(20),int,int,varchar(20),varchar(20)) as $$
    BEGIN   
        INSERT INTO player_list VALUES($1,$2,$3,$4,$5);
    END
$$ LANGUAGE plpgsql;



select altaPlayer('Drazen Petrovic',52,80,'Escolta','Cibona');

2 个答案:

答案 0 :(得分:2)

必须指定函数结果类型:

create or replace function altaplayer ( varchar(20),int,int,varchar(20),varchar(20)) 
returns void -- !!!
as $$
    begin   
        insert into player_list values($1,$2,$3,$4,$5);
    end
$$ language plpgsql;

答案 1 :(得分:1)

您错过了关键字RETURNS。

create or replace function altaPlayer
    (varchar(20),int,int,varchar(20),varchar(20)) 
        RETURNS void as $$