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

Re: timestamp/function question

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Soma Interesting <dfunct(at)telus(dot)net>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: timestamp/function question
Date: 2001-03-29 15:56:34
Message-ID: 22404.985881394@sss.pgh.pa.us (view raw or flat)
Thread:
Lists: pgsql-general
Soma Interesting <dfunct(at)telus(dot)net> writes:
> Why does the following code return the exact same value each time, instead 
> of a value based on the current time?

> CREATE FUNCTION memb_num () RETURNS INT4 AS '
> 	BEGIN
> 		RETURN date_part(''epoch'', CURRENT_DATE);
> 	END;
> ' LANGUAGE 'plpgsql';

Because you asked for a value based on the current *date*.
If you waited till tomorrow and tried again, then you'd get a
different answer.  Perhaps you want

 		RETURN date_part(''epoch'', CURRENT_TIMESTAMP);

			regards, tom lane

In response to

Responses

pgsql-general by date

Next:From: Tom LaneDate: 2001-03-29 16:00:39
Subject: Re: Pgsql-7.1RC1: SET SEED = <something>
Previous:From: chris markiewiczDate: 2001-03-29 15:46:21
Subject: ExecSQL NullPtrEx...conn timeout?

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