Skip site navigation (1) Skip section navigation (2)

Function with now() | time 'now' | etc...

From: edipoelder(at)ig(dot)com(dot)br
To: pgsql-sql(at)postgresql(dot)org
Subject: Function with now() | time 'now' | etc...
Date: 2001-03-28 18:59:08
Message-ID: 200103281859.f2SIxDU52128@mail.postgresql.org (view raw or flat)
Thread:
Lists: pgsql-sql
Hi all, 

    I wrote the folling function: 

DROP FUNCTION PROC_TESTE(INTEGER); 
CREATE FUNCTION PROC_TESTE(INTEGER) RETURNS INTEGER AS ' 
DECLARE 
        SEQ RECORD; 
BEGIN 
        SELECT NEXTVAL(''TEMPOS_ID_SEQ'') AS ID INTO SEQ; 
        INSERT INTO TEMPOS (ID, INICIO) VALUES (SEQ.ID, NOW());              
           FOR I IN 1..$1 LOOP 
                INSERT INTO TESTE(VALOR) VALUES (RANDOM()*$1); 
        END LOOP; 
        UPDATE TEMPOS SET FIM = NOW() WHERE ID = SEQ.ID; 
        RETURN SEQ.ID; 
END;' 
LANGUAGE 'PLPGSQL'; 

    And all times I run it ("select proc_teste(10000);"), i got the folling 
behavour: 

teste=> SELECT * FROM TEMPOS; 
  inicio  |   fim    | id 
----------+----------+---- 
 15:12:17 | 15:12:17 | 23 
 15:12:18 | 15:12:18 | 24 
(...) 

    It doesn't getting different times on each execution. I also tried put 
"timestamp 'now'" insted "now()". What am I doing wrong? 

    Thank you, 

    Edipo Elder 
    [edipoelder(at)ig(dot)com(dot)br] 

_________________________________________________________
Oi! Voc quer um iG-mail gratuito?
Ento clique aqui: http://www.ig.com.br/paginas/assineigmail.html


Responses

pgsql-sql by date

Next:From: Martin JacobsDate: 2001-03-28 19:16:54
Subject: Re: String REPLACE function
Previous:From: Roberto MelloDate: 2001-03-28 18:51:05
Subject: Re: Oracle -> Postgresql migration

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group