pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
Function with now() | time 'now' | etc...
3+ messages / 3 participants
[nested] [flat]

* Function with now() | time 'now' | etc...
@ 2001-03-28 18:59  edipoelder@ig.com.br
  0 siblings, 1 reply; 3+ messages in thread

From: edipoelder@ig.com.br @ 2001-03-28 18:59 UTC (permalink / raw)
  To: 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@ig.com.br] 

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




^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: Function with now() | time 'now' | etc...
@ 2001-03-28 19:22  Tom Lane <tgl@sss.pgh.pa.us>
  parent: edipoelder@ig.com.br
  0 siblings, 1 reply; 3+ messages in thread

From: Tom Lane @ 2001-03-28 19:22 UTC (permalink / raw)
  To: edipoelder@ig.com.br; +Cc: pgsql-sql

edipoelder@ig.com.br writes:
>     It doesn't getting different times on each execution. I also tried put 
> "timestamp 'now'" insted "now()". What am I doing wrong? 

now() is defined to return the time of the start of the current
transaction.  It won't change value inside a transaction.  See
http://www.postgresql.org/devel-corner/docs/postgres/functions-datetime.html#FUNCTIONS-DATETIME-CURR...

			regards, tom lane



^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: Function with now() | time 'now' | etc...
@ 2001-03-29 11:38  Cedar Cox <cedarc@visionforisrael.com>
  parent: Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 0 replies; 3+ messages in thread

From: Cedar Cox @ 2001-03-29 11:38 UTC (permalink / raw)
  To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: edipoelder@ig.com.br; pgsql-sql


> edipoelder@ig.com.br writes:
> >     It doesn't getting different times on each execution. I also tried put 
> > "timestamp 'now'" insted "now()". What am I doing wrong? 
> 
> now() is defined to return the time of the start of the current
> transaction.  It won't change value inside a transaction.  See
> http://www.postgresql.org/devel-corner/docs/postgres/functions-datetime.html#FUNCTIONS-DATETIME-CURR...

What about CURRENT_TIMESTAMP?  (This is standard SQL isn't it?)




^ permalink  raw  reply  [nested|flat] 3+ messages in thread


end of thread, other threads:[~2001-03-29 11:38 UTC | newest]

Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2001-03-28 18:59 Function with now() | time 'now' | etc... edipoelder@ig.com.br
2001-03-28 19:22 ` Tom Lane <tgl@sss.pgh.pa.us>
2001-03-29 11:38   ` Cedar Cox <cedarc@visionforisrael.com>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox