Results 1 to 5 of 5
  1. #1
    Join Date
    Dec 2012
    Posts
    30

    Unanswered: SQL ERROR: syntax errorat or near "do". Stato SQL: 42601

    Hi to All,
    could Someone resolve this problem?


    If I execute the following function I have the following ERROR


    Code:
    do
    $body$
    declare 
      week_nr integer;
      anno_nr integer;
      stmt    text;
    begin
      week_nr := 1;
      anno_nr := extract(year from current_date);
    
    --Nel Mentre che il valore settimana e' minore di 53 : 1)Esegui l'inserzione; 2) Aumenta di 1 il valore di settimana e
    --riesegui l'inserzione. Quando sei arrivato a week=53 esci
    
    --Per gli anni da quello attuale, a ritroso, sino al 2009 inserisci in una tabella(generata automaticamente) per
    --ogni anno i dati della settimana . Vale per articoli, reparti, sottoreparti
    for anno_nr in reverse anno_nr..2009 loop
                             for week_nr in 1..53 loop
                                stmt := 'insert into anno'||anno_nr::text||
                                        ' select fkid_reparto, SUM(totale), settimana '||
                                        'from righe_scontrino '||
                                        'where settimana = '||week_nr::text||
                                        ' and anno= '||anno_nr::text||
                                        ' GROUP BY fkid_reparto, settimana'; 
                                        execute stmt;
                                        week_nr := week_nr + 1;
                                 end loop;
      anno_nr := anno_nr -1;
      week_nr := 1;
      end loop;
    end;
    $body$

    HERE IS THE ERROR MESSAGE:

    Code:
    SQL ERROR:  syntax errorat or near "do"
    
    
    **********************Errore****************************
    ERROR:  syntax erro rat or near "do"
    Stato SQL: 42601
    Tanks in advance.
    Gianni Pinna

  2. #2
    Join Date
    Nov 2003
    Posts
    2,935
    Provided Answers: 12
    This feature is not available in 8.4, it was introduced in 9.0.

    Please read the manual
    I will not read nor answer questions where the SQL code is messy and not formatted properly using [code] tags: http://www.dbforums.com/misc.php?do=bbcode#code

    Tips for good questions:

    http://tkyte.blogspot.de/2005/06/how...questions.html
    http://wiki.postgresql.org/wiki/SlowQueryQuestions
    http://catb.org/esr/faqs/smart-questions.html

  3. #3
    Join Date
    Dec 2012
    Posts
    30
    Hi Shammat,

    tank You very much for Your Kind and prompt reply.
    I tried to find in the manual the command "do" but I did'nt find it.

    Could You suggest me if is there a way to adapt the function above to 8.4.?
    Tanks again.
    Tanks in advance.
    Gianni Pinna.

  4. #4
    Join Date
    Nov 2003
    Posts
    2,935
    Provided Answers: 12
    Quote Originally Posted by Gianni Pinna View Post
    I tried to find in the manual the command "do" but I did'nt find it.
    As this is not available in 8.4, you will not find it there. You need to check the 9.x manuals (see the chapter "SQL Commands" in the chapter "Reference")

    Could You suggest me if is there a way to adapt the function above to 8.4.?
    You need to create a function and call it. There is no equivalent to anonymous code blocks in 8.4
    I will not read nor answer questions where the SQL code is messy and not formatted properly using [code] tags: http://www.dbforums.com/misc.php?do=bbcode#code

    Tips for good questions:

    http://tkyte.blogspot.de/2005/06/how...questions.html
    http://wiki.postgresql.org/wiki/SlowQueryQuestions
    http://catb.org/esr/faqs/smart-questions.html

  5. #5
    Join Date
    Dec 2012
    Posts
    30
    Hi Shammat,

    You are always Kind and Your answers are perfect and intelligent.
    Tank You very much, Shammat.
    Sincerly.
    Gianni Pinna

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •