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

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

From: Guy Fraser <guy(at)incentre(dot)net>
To: "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-13 14:44:33
Message-ID: 411CD3D1.2090800@incentre.net (view raw or flat)
Thread:
Lists: pgsql-novicepgsql-sql
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....
>
>  
>

In response to

pgsql-novice by date

Next:From: Sean DavisDate: 2004-08-13 14:47:08
Subject: Re: Query output
Previous:From: Eduardo Vázquez RodríguezDate: 2004-08-13 14:22:58
Subject: Query output

pgsql-sql by date

Next:From: PentilianDate: 2004-08-13 16:05:39
Subject: Re: Wierd Error on update
Previous:From: Philippe LangDate: 2004-08-13 08:52:11
Subject: Re: function expression in FROM may not refer to other relations of same query level

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