Re: [SQL] how to cast localtimestamp to bigint???

From: "Pradeepkumar, Pyatalo (IE10)" <Pradeepkumar(dot)Pyatalo(at)honeywell(dot)com>
To: gry(at)ll(dot)mit(dot)edu, "Pradeepkumar, Pyatalo (IE10)" <Pradeepkumar(dot)Pyatalo(at)honeywell(dot)com>
Cc: pgsql-novice(at)postgresql(dot)org
Subject: Re: [SQL] how to cast localtimestamp to bigint???
Date: 2004-08-17 04:17:05
Message-ID: 77ED2BF75D59D1439F90412CC5B109741054606A@ie10-sahara.hiso.honeywell.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice


Hi all,

Thanx for all your valuable inputs. I have tried all the suggestions....they
seem to be working fine....Thanks a lot.

-----Original Message-----
From: george young [mailto:gry(at)ll(dot)mit(dot)edu]
Sent: Friday, August 13, 2004 11:05 PM
To: Pradeepkumar, Pyatalo (IE10)
Cc: pgsql-novice(at)postgresql(dot)org
Subject: Re: [NOVICE] [SQL] how to cast localtimestamp to bigint???

On Thu, 12 Aug 2004 07:47:06 -0700
"Pradeepkumar, Pyatalo (IE10)" <Pradeepkumar(dot)Pyatalo(at)honeywell(dot)com> threw
this fish to the penguins:

> I am having a table something like this....
>
> CREATE TABLE(PointId integer, PointName varchar(50),PointType integer,
> createtime bigint);
>
> where createtime is the current timestamp when the tuple is inserted.
>
> now how do I insert values into the above table. Is there a way to cast
> timestamp to bigint.
> Also can anyone suggest as to which date function to use -
> CURRENT_TIMESTAMP, LOCALTIMESTAMP, timeofday(), now....

You could use(from
http://www.postgresql.org/docs/7.4/static/functions-datetime.html#FUNCTIONS-
DATETIME-EXTRACT)

EXTRACT (field FROM source)
epoch

For date and timestamp values, the number of seconds since 1970-01-01
00:00:00-00 (can be negative); for interval values, the total number of
seconds in the interval

e.g.:

select CURRENT_TIMESTAMP, extract('epoch' from CURRENT_TIMESTAMP)::bigint;
(1 row)
timestamptz | date_part
-------------------------------+------------
2004-08-13 13:27:30.715408-04 | 1092418051

The bigint cast will round to the nearest second.

See:

http://www.postgresql.org/docs/7.4/static/functions-datetime.html#FUNCTIONS-
DATETIME-CURRENT

for subtleties of various current time/date functions.

-- George Young
--
"Are the gods not just?" "Oh no, child.
What would become of us if they were?" (CSL)

---------------------------(end of broadcast)---------------------------
TIP 3: if posting/reading through Usenet, please send an appropriate
subscribe-nomail command to majordomo(at)postgresql(dot)org so that your
message can get through to the mailing list cleanly

Browse pgsql-novice by date

  From Date Subject
Next Message Thuffman00 2004-08-17 07:59:17 Another date/time question using libpq
Previous Message Davis, Sean (NIH/NHGRI) 2004-08-16 18:43:33 Re: New coloumns