Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/72.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/postgresql/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
函数count()是PL/Pgsql中的一个变量_Sql_Postgresql_Count_Plpgsql - Fatal编程技术网

函数count()是PL/Pgsql中的一个变量

函数count()是PL/Pgsql中的一个变量,sql,postgresql,count,plpgsql,Sql,Postgresql,Count,Plpgsql,我有个奇怪的问题。在数据库中,我安装了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 MOD

我有个奇怪的问题。在数据库中,我安装了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;
我要做什么来计算行数?

问题在于:

DECLARE count integer; 

您将
count
声明为函数变量。将变量的声明更改为其他内容。像
cnt
count\u某物

这是SQL和PL/pgSQL标识符的冲突。请升级。现代版本使用了一种更智能的算法,将占位符放置到嵌入式SQL中,主要是在识别冲突时,会引发更详细、更可读的异常


在这种情况下,你是一个快乐的人。可能有一个奇怪的不可见和不需要的行为-因此语法错误更好。

count
是一个关键字。尝试使用
rowcount
或其他方法。顺便说一句,尝试阅读一些关于postgres和SQL的书籍和/或手册。您提供的函数效率低下,逻辑上不正确。
DECLARE count integer;