pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Guy Fraser <guy@incentre.net>
To: Pradeepkumar, Pyatalo (IE10) <Pradeepkumar.Pyatalo@honeywell.com>
Cc: pgsql-novice@postgresql.org
Subject: Re: [SQL] how to cast localtimestamp to bigint???
Date: Fri, 13 Aug 2004 08:44:33 -0600
Message-ID: <411CD3D1.2090800@incentre.net> (raw)
In-Reply-To: <77ED2BF75D59D1439F90412CC5B109741027FF0F@ie10-sahara.hiso.honeywell.com>
References: <77ED2BF75D59D1439F90412CC5B109741027FF0F@ie10-sahara.hiso.honeywell.com>

You don't need to use a bigint, read the documentation on data types.

There are a number of different things you can use for a timestamp, here
are a few :

abstime
abstime with timezone
timestamp
timestamp with timezone

Then when you are inserting your data, you can use 'now' as the time.

Eg.
CREATE TABLE pointy_stuff (
    PointId integer,
    PointName varchar(50),
    PointType integer,
    CreateTime abstime
);

INSERT INTO pointy_stuff (
    PointId,
    PointName,
    PointType,
    CreateTime
) VALUES (
    '12345',
    'point1',
    '1',
    'now'
);

I believe abstime is the smallest timestamp, but I could be wrong.

To output the data as a bigint I believe you can use this.

SELECT
    PointId,
    PointName,
    PointType,
    date_part('epoch',CreateTime) as unix_ts
FROM
    pointy_stuff
;

Hope that helps.

Pradeepkumar, Pyatalo (IE10) wrote:

>Hi,
>
>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....
>
>  
>



view thread (4+ messages)  latest in thread

Message-ID: <411CD3D1.2090800@incentre.net>
Permalink:  ../411CD3D1.2090800@incentre.net/
Also on:    postgresql.org/message-id/411CD3D1.2090800@incentre.net

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: guy@incentre.net, Pradeepkumar.Pyatalo@honeywell.com, pgsql-novice@postgresql.org
  Subject: Re: [SQL] how to cast localtimestamp to bigint???
  In-Reply-To: <411CD3D1.2090800@incentre.net>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

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