Postgres



  • I'm trying to reschedule sql server in postgres. Makes a mistake of syntaxis:

    ERROR: syntax error at or near "count."

    I think I wrote it right. http://www.postgresql.org/docs/9.5/static/plpgsql-statements.html#PLPGSQL-STATEMENTS-ASSIGNMENT

    _count := (SELECT count(score) from   PaperReviewing wh...
    

    (Renewed) That's the code, now there's a mistake.

    syntax error at end of input

    and points to the US$

    CREATE OR REPLACE FUNCTION SubmitReview(_paper_id INT, _reviewer_id INT, _score INT)
    RETURNS VOID AS $$
    DECLARE
        _mark float; 
        _count INT;
    BEGIN
         _mark := 0;
        _count := 0;
        IF Exists(Select paper_id, reviewer_id from PaperReviewing where paper_id=_paper_id and reviewer_id =_reviewer_id )AND _score in (1,2,3,4,5,6,7) then
            UPDATE PaperReviewing
                SET score = _score;
               _count := (SELECT count(score) from   PaperReviewing where paper_id = _paper_id );
            If ( _Count)>=3 then
                 _mark := cast( (Select sum(score) from PaperReviewing where paper_id = _paper_id) as float)/_Count;
                IF _mark>4 then
                    UPDATE Paper
                        SET accepted=1 
                        where Id = @paper_id;
                else 
                    UPDATE Paper
                        Set accepted = 0 
                        where Id = @paper_id;
                        end if;
        else 
        RAISE EXCEPTION 'Not implemented yet';
    END IF;
    END; 
    $$ LANGUAGE plpgsql;
    

  • QA Engineer

    Where's the code? before _count :=...? There's a suspicion that you're a comma point at the end of the previous line, just like that.

    _count := (SELECT count(score) from   PaperReviewing where paper_id = _paper_id );
    

    A second error in the consequence of the lack of closure of one of the needles. You have 3 IF and only 2 END IF.


Log in to reply
 


Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2