X-Original-To: pgsql-novice-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 03C7D5E3E30 for ; Fri, 13 Aug 2004 14:35:27 -0300 (ADT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 27634-04 for ; Fri, 13 Aug 2004 17:35:23 +0000 (GMT) Received: from ll.mit.edu (LLMAIL.LL.MIT.EDU [129.55.12.40]) by svr1.postgresql.org (Postfix) with ESMTP id 2A3C75E37CE for ; Fri, 13 Aug 2004 14:35:12 -0300 (ADT) Received: (from smtp@localhost) by ll.mit.edu (8.12.10/8.8.8) id i7DHZ18w022267; Fri, 13 Aug 2004 13:35:01 -0400 (EDT) Received: from sty.llan.ll.mit.edu( ), claiming to be "sty.llan" via SMTP by llpost, id smtpdAAAXSaiuR; Fri Aug 13 13:34:57 2004 Date: Fri, 13 Aug 2004 13:34:57 -0400 From: george young To: "Pradeepkumar, Pyatalo (IE10)" Cc: pgsql-novice@postgresql.org Subject: Re: [SQL] how to cast localtimestamp to bigint??? Message-Id: <20040813133457.12f50ed5.gry@ll.mit.edu> In-Reply-To: <77ED2BF75D59D1439F90412CC5B109741027FF0F@ie10-sahara.hiso.honeywell.com> References: <77ED2BF75D59D1439F90412CC5B109741027FF0F@ie10-sahara.hiso.honeywell.com> Reply-To: gry@ll.mit.edu Organization: MIT Lincoln Laboratory X-Mailer: Sylpheed version 0.9.10 (GTK+ 1.2.10; i686-pc-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= X-Spam-Level: X-Archive-Number: 200408/176 X-Sequence-Number: 10713 On Thu, 12 Aug 2004 07:47:06 -0700 "Pradeepkumar, Pyatalo (IE10)" 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)