我需要使用此功能将团队从pl_raw加载到名为game的新表。 在pl_raw中是所有数据。现在..这个函数是为了为表格订购数据......
CREATE OR REPLACE FUNCTION loadGames() RETURNS void AS $$
BEGIN
IF (SELECT * from pldata.pl_raw where venue = 'Away') THEN
INSERT INTO definitiu.game (date_game, home_team, away_team)
SELECT game_date, opposition_id,team_id from pldata.pl_raw;
ELSIF (SELECT * from pldata.pl_raw where venue = 'Home') THEN
INSERT INTO definitiu.game (date_game, home_team, away_team)
SELECT game_date, team_id, opposition_id from pldata.pl_raw;
END IF;
END; $$
LANGUAGE PLPGSQL;
函数compile,但是,当我执行这个函数时,Postgres会返回这个错误:
错误:子查询必须只返回一列 第1行:SELECT(SELECT * from pldata.pl_raw where venue ='Away') ^ QUERY:SELECT(SELECT * from pldata.pl_raw where venue ='Away') 语境:PL / pgSQL函数loadgames()第4行,IF
**********错误**********
错误:子查询必须只返回一列 SQL状态:42601 上下文:PL / pgSQL函数loadgames()第4行在IF
答案 0 :(得分:0)
使用EXISTS:
IF EXISTS (SELECT * from pldata.pl_raw where venue = 'Away') THEN