2014-02-11 65 views
0

我想在Postgres 9.3.0中的長時間運行的函數的消息窗格中顯示狀態信息。當函數執行開始時,Postgres只評估localtime一次,而不是我稱之爲值。它重複輸出相同的值。我怎樣才能解決這個問題?Postgres current_time evaluation

我迭代通過這樣的光標:

FOR record IN cursor LOOP 
    PERFORM otherFunction(<id field from the record>); 
    If mod(i,100)=0 THEN 
     RAISE NOTICE '% pct complete',round(i::numeric/recordcount::numeric*100); 
     RAISE NOTICE '%', localtime; 
     i=i+1; 
    END IF; 
END LOOP; 

謝謝!

+1

使用['clock_timestamp'](http://www.postgresql.org/docs/current/static/functions-datetime.html#FUNCTIONS-DATETIME-CURRENT)。 –

回答

1

請參閱the user manual for current date/time

localtime,如current_timestamp,在整個交易中是固定的。

如果您想在每次通話時享用新鮮時間,請使用clock_timestamp。請注意,與localtime不同,它會返回timestamp with time zone,因此您不妨將其轉換爲at time zone或將其轉換。

+0

感謝Milen和Craig的回答。 –

相關問題