user3260663
user3260663

Reputation: 31

postgres's alternative for "fetch_status"

I have a question, I need an alternative to "fetch_STATUS". I have to translate the next block of code from Sql Servers to Postgres.

   WHILE (@@fetch_status <> -1)
       BEGIN
        IF (@@fetch_status <> -2)
            BEGIN
            IF (@OrdenSecuencial = '' OR LOWER(@OrdenSecuencial) = 'null' OR @OrdenSecuencial IS NULL)
            BEGIN
                Exec SPUpdateSecuencial @ArbolNodoID, @OrdenSecuencial output
                IF @@ERROR <> 0 Goto DeleteError
            END
        END
        FETCH NEXT FROM CU_ArbolNodo INTO @ArbolNodoID,@Orden, @OrdenSecuencial,@ArbolNodoIdPadre
       END

Upvotes: 2

Views: 1029

Answers (2)

In SQL Server:

WHILE (@@fetch_status <> -1)  
           BEGIN  
                IF (@@fetch_status <> -2)

In PostgreSQL:

    WHILE (FOUND) LOOP  
           BEGIN  
                IF (FOUND)   
                  [...]  
                END IF;  
           END;  
       END LOOP;  

I answered a similar question here: https://stackoverflow.com/a/39966688/6934093

Upvotes: 3

user330315
user330315

Reputation:

Something like:

for result_row in (select ArbolNodoID, OrdenSecuencial
                   from some_table) 
loop
   if (lower(result_row.OrdenSecuencial) in ('', 'null') or result_row.OrdenSecuencial is null) then 
     perform SPUpdateSecuencial(result_row.ArbolNodoID, result_row.OrdenSecuencial);
   end if;
end loop;

I don't know what the output keyword in T-SQL is supposed to do when calling the stored procedure.

Upvotes: 0

Related Questions