I have a function in PL/pgSQL which needs the current time in seconds
expressed as an int4. In 7.1 I was able to get this (I thought) with
date_part(''epoch'', timestamp ''now'') . That doesn't seem to work for me
in last week's -current.

Here's the PLpgSQL:

        v_seed := date_part(''epoch'', timestamp ''now'');

And here's the output:

NOTICE:  Error occurred while executing PL/pgSQL function
NOTICE:  line 4 at assignment
ERROR:  Timestamp with time zone units 'epoch' not recognized

What's the best way to do this?

Take care,

Bill


Thu, 11 Oct 2001 09:17:45 -0700 (PDT)
Bill Studenmund <wrstuden@netbsd.org>
How do I get the current time in seconds in the unix epoch?
Bill Studenmund <wrstuden@netbsd.org> writes:
> In 7.1 I was able to get this (I thought) with
> date_part(''epoch'', timestamp ''now'') . That doesn't seem to work for me
> in last week's -current.

Indeed: in 7.1 I can do

test71=# select date_part('epoch', timestamp 'now');
 date_part
------------
 1002946239
(1 row)

but current sources give

regression=# select date_part('epoch', timestamp 'now');
ERROR:  Timestamp with time zone units 'epoch' not recognized

Thomas, I think you broke something.

			regards, tom lane

Sat, 13 Oct 2001 00:12:38 -0400
Tom Lane <tgl@sss.pgh.pa.us>
Re: How do I get the current time in seconds in the unix epoch? 
> I have a function in PL/pgSQL which needs the current time in seconds
> expressed as an int4. In 7.1 I was able to get this (I thought) with
> date_part(''epoch'', timestamp ''now'') . That doesn't seem to work for me
> in last week's -current.
>
> Here's the PLpgSQL:
>
>         v_seed := date_part(''epoch'', timestamp ''now'');
>
> And here's the output:
>
> NOTICE:  Error occurred while executing PL/pgSQL function
> NOTICE:  line 4 at assignment
> ERROR:  Timestamp with time zone units 'epoch' not recognized

Hmmm.  I don't know why date_part isn't working, but I now only use the
EXTRACT syntax for maximum SQL compatibility.  ie. Do this instead:

v_seed := EXTRACT (EPOCH FROM CURRENT_TIMESTAMP);

Cheers,

Chris


Mon, 15 Oct 2001 10:42:00 +0800
"Christopher Kings-Lynne" <chriskl@familyhealth.com.au>
Re: How do I get the current time in seconds in the unix epoch?
> > In 7.1 I was able to get this (I thought) with
> > date_part(''epoch'', timestamp ''now'') . That doesn't seem to work for me
> > in last week's -current.
> Thomas, I think you broke something.

It was actually a side effect of changing the date/time parser to no
longer ignore unrecognized text fields. The previous behavior has been
there from the Beginning, and the new behavior meant that the search
routine no longer returns "ignore" as a status (which caused the calling
routine to drop into the "special case" tests including "epoch").

Anyway, I've got patches, so no worries...

                       - Thomas

Mon, 15 Oct 2001 05:31:58 +0000
Thomas Lockhart <lockhart@fourpalms.org>
Re: How do I get the current time in seconds in the unix 
On Mon, 15 Oct 2001, Christopher Kings-Lynne wrote:

> Hmmm.  I don't know why date_part isn't working, but I now only use the
> EXTRACT syntax for maximum SQL compatibility.  ie. Do this instead:
>
> v_seed := EXTRACT (EPOCH FROM CURRENT_TIMESTAMP);

Unfortunatly that gives the same error. I think the problem is that the
underlying code isn't liking the EPOCH timezone. Tom mentioned he had
patches.

Take care,

Bill


Mon, 15 Oct 2001 06:29:15 -0700 (PDT)
Bill Studenmund <wrstuden@netbsd.org>
Re: How do I get the current time in seconds in the unix