2012-09-20 49 views
3

我們的軟件出現問題,爲了解決這個問題,我必須編寫一個存儲過程,作爲升級安裝升級過程的一部分運行。此存儲過程需要查找特定表中符合特定條件的每一行並更新該行。出於內部原因,更新必須通過我們爲插入和更新數據專門編寫的存儲過程完成。如何修復這個PostgreSQL 9.1存儲過程?

這是我寫來解決這個問題的存儲過程:

CREATE OR REPLACE FUNCTION FixDataProblem() RETURNS VOID AS $$ 
DECLARE 
    FixCursor NO SCROLL CURSOR FOR 
     SELECT * FROM MyTable WHERE ProblemColumn IN ('?', 'PR'); 
    RowToUpdate   MyTable%ROWTYPE; 
BEGIN 
    -- Open the cursor 
    OPEN FixCursor; 

    -- Start a loop 
    LOOP 
     -- Fetch the next row from thr cursor 
     FETCH FixCursor INTO RowToUpdate; 

     -- Did we get anything back? 
     IF RowToUpdate IS NULL THEN 
      -- We didn't. Exit the loop 
      EXIT; 
     END IF; 

     -- Call the UpsertMyTable stored procedure to set the ProblemColumn column to NULL 
     SELECT CarSystem.UpsertMyTable(RowToUpdate.RowId, 
           RowToUpdate.ForeignId, 
           RowToUpdate.CountryId, 
           NULL, 
           RowToUpdate.Plate, 
           RowToUpdate.HashedData, 
           RowToUpdate.PlateClassId, 
           RowToUpdate.AlarmClassId, 
           RowToUpdate.BeginDate, 
           RowToUpdate.EndDate, 
           RowToUpdate.ListPriorityId, 
           RowToUpdate.VehicleTypeId, 
           RowToUpdate.MakeId, 
           RowToUpdate.ModelId, 
           RowToUpdate.Year, 
           RowToUpdate.ColorId, 
           RowToUpdate.Notes, 
           RowToUpdate.OfficerNotes, 
           NULL, 
           UUID_GENERATE_V4()); 
    END LOOP; 

    -- Close the cursor 
    CLOSE ListDetailsCursor; 
END; 
$$ LANGUAGE plpgsql; 

此存儲過程很好,但是當我運行它,我得到:

ERROR: query has no destination for result data 
HINT: If you want to discard the results of a SELECT, use PERFORM instead. 
CONTEXT: PL/pgSQL function "fixdataproblem" line 22 at SQL statement 


********** Error ********** 

ERROR: query has no destination for result data 
SQL state: 42601 
Hint: If you want to discard the results of a SELECT, use PERFORM instead. 
Context: PL/pgSQL function "fixdataproblem" line 22 at SQL statement 

我該如何解決這個問題問題?我相信我正確調用存儲過程。我真的不知道這個存儲過程的問題是什麼。

感謝

託尼

+2

爲什麼不按照錯誤信息中的建議? –

回答

6

它說在那裏:

ERROR: query has no destination for result data 
HINT: If you want to discard the results of a SELECT, use PERFORM instead. 
CONTEXT: PL/pgSQL function "fixdataproblem" line 22 at SQL statement 

而且在第22行:

-- Call the UpsertMyTable stored procedure to set the ProblemColumn column to NULL 
    SELECT CarSystem.UpsertMyTable(RowToUpdate.RowId, 
    ... 

變化從SELECTPERFORM。爲什麼請參閱PERFORM

+0

每隔一段時間我調用一個存儲過程,它總是在SELECT語句中。當我嘗試使用'PERFORM'調用'FixDataProblem'存儲過程時,出現語法錯誤。我沒有做出的連接是需要'PERFORM'來調用'UpsertMyTable'存儲過程。謝謝 –