我有一个奇怪的问题。在数据库中,我安装了 plpgsql 语言,但在此代码中:
CREATE OR REPLACE FUNCTION add_sala() RETURNS void AS
$BODY$
DECLARE i integer;
DECLARE IdConfAux integer;
DECLARE count integer;
DECLARE a integer;
BEGIN
LOCK TABLE "TabelaSalas" IN ACCESS EXCLUSIVE MODE NOWAIT;
UPDATE "TabelaSalas" SET "NumJogadoresAtual" = 0, "EstadoSala"= 0,"CronometroIniciado"=0, "TempoInicioJogo"=15
WHERE "NumJogadoresAtual"<0;
CREATE TEMP TABLE tempIds ON COMMIT DROP AS
SELECT "IdConf" FROM "ConfiguracaoSalas" WHERE "Senha" IS NULL;
SELECT COUNT(*) INTO count FROM tempIds;
RAISE NOTICE 'count = % ',count;
WHILE count > 0 LOOP
SELECT "IdConf" INTO IdConfAux FROM tempIds LIMIT 1;
SELECT COUNT(*) INTO i FROM "TabelaSalas"
WHERE IdConfAux = "IdConf"
AND "NumJogadoresAtual" = 0 ;
RAISE NOTICE 'i= % IDCONF = %', i,IdConfAux;
IF i=0 THEN
RAISE NOTICE 'entrou %',IdConfAux;
INSERT INTO "TabelaSalas"("IdConf","DataCriacao","OrdemQuestoes","NumJogadoresAtual","TempoInicioJogo","CronometroIniciado","EstadoSala")
SELECT IdConfAux, NOW(),"OrdemQuestoes",0,15,0,0 FROM "TabelaSalas" LIMIT 1 ;
END IF;
DELETE FROM tempIds WHERE "IdConf" IN (SELECT * FROM tempIds LIMIT 1);
i=1;
count = count - 1;
END LOOP;
END;
$BODY$
LANGUAGE plpgsql VOLATILE
COST 100;
我有这个错误。看起来 COUNT 被认为是函数的变量:
ERRO: erro de sintaxe em ou próximo a "("
LINE 1: SELECT $1 () FROM tempIds
^
QUERY: SELECT $1 () FROM tempIds
CONTEXT: SQL statement in PL/PgSQL function "add_sala" near line 15.
我必须做些什么来计算行数?