pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
EPOCH TIMESTAMP Conversion Problem
5+ messages / 4 participants
[nested] [flat]

* EPOCH TIMESTAMP Conversion Problem
@ 2007-11-07 10:37 Amitanand Chikorde <amit99rs@gmail.com>
  2007-11-07 15:35 ` Re: EPOCH TIMESTAMP Conversion Problem Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 1 reply; 5+ messages in thread

From: Amitanand Chikorde @ 2007-11-07 10:37 UTC (permalink / raw)
  To: pgsql-sql

hi all,

    I have a table 'myTable'.
    There is an attribute  in the table as,


Column      |            Type             | Modifiers
-----------------+-----------------------------+-----------
 mydate     | timestamp without time zone | not null


I want to convert MAX(mydate) from myTable to Epoch.


SELECT EXTRACT(EPOCH FROM TIMESTAMP WITHOUT TIME ZONE '2007-11-01
17:42:01.81693') ::int4;


How the above query can be used to convert MAX(mydate) to EPoch value?
Is there any other query that I can use?
I think it is not worth to write a function/procedure to just replace
the value in a query?

     Please HELP...................

Thanks in advance


-- 
Amitanand N. Chikorde.
Software Engineer
==================================
cat /dev/zero >/dev/null
==================================



^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* Re: EPOCH TIMESTAMP Conversion Problem
  2007-11-07 10:37 EPOCH TIMESTAMP Conversion Problem Amitanand Chikorde <amit99rs@gmail.com>
@ 2007-11-07 15:35 ` Tom Lane <tgl@sss.pgh.pa.us>
  2008-01-01 14:28   ` Re: EPOCH TIMESTAMP Conversion Problem Louis-David Mitterrand <vindex+lists-pgsql-sql@apartia.org>
  0 siblings, 1 reply; 5+ messages in thread

From: Tom Lane @ 2007-11-07 15:35 UTC (permalink / raw)
  To: Amitanand Chikorde <amit99rs@gmail.com>; +Cc: pgsql-sql

"Amitanand Chikorde" <amit99rs@gmail.com> writes:
> I want to convert MAX(mydate) from myTable to Epoch.

Do you mean
	SELECT EXTRACT(EPOCH FROM MAX(mydate)) FROM myTable

			regards, tom lane



^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* Re: EPOCH TIMESTAMP Conversion Problem
  2007-11-07 10:37 EPOCH TIMESTAMP Conversion Problem Amitanand Chikorde <amit99rs@gmail.com>
  2007-11-07 15:35 ` Re: EPOCH TIMESTAMP Conversion Problem Tom Lane <tgl@sss.pgh.pa.us>
@ 2008-01-01 14:28   ` Louis-David Mitterrand <vindex+lists-pgsql-sql@apartia.org>
  2008-01-01 19:03     ` Re: EPOCH TIMESTAMP Conversion Problem Tom Lane <tgl@sss.pgh.pa.us>
  2008-01-01 19:32     ` Re: EPOCH TIMESTAMP Conversion Problem Michael Glaesemann <grzm@seespotcode.net>
  0 siblings, 2 replies; 5+ messages in thread

From: Louis-David Mitterrand @ 2008-01-01 14:28 UTC (permalink / raw)
  To: pgsql-sql

On Wed, Nov 07, 2007 at 10:35:08AM -0500, Tom Lane wrote:
> "Amitanand Chikorde" <amit99rs@gmail.com> writes:
> > I want to convert MAX(mydate) from myTable to Epoch.
> 
> Do you mean
> 	SELECT EXTRACT(EPOCH FROM MAX(mydate)) FROM myTable

Is using casts for the same purpose deprecated?

	SELECT current_date::timestamp::abstime::int4;

Or less efficient?



^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* Re: EPOCH TIMESTAMP Conversion Problem
  2007-11-07 10:37 EPOCH TIMESTAMP Conversion Problem Amitanand Chikorde <amit99rs@gmail.com>
  2007-11-07 15:35 ` Re: EPOCH TIMESTAMP Conversion Problem Tom Lane <tgl@sss.pgh.pa.us>
  2008-01-01 14:28   ` Re: EPOCH TIMESTAMP Conversion Problem Louis-David Mitterrand <vindex+lists-pgsql-sql@apartia.org>
@ 2008-01-01 19:03     ` Tom Lane <tgl@sss.pgh.pa.us>
  1 sibling, 0 replies; 5+ messages in thread

From: Tom Lane @ 2008-01-01 19:03 UTC (permalink / raw)
  To: Louis-David Mitterrand <vindex+lists-pgsql-sql@apartia.org>; +Cc: pgsql-sql

Louis-David Mitterrand <vindex+lists-pgsql-sql@apartia.org> writes:
> On Wed, Nov 07, 2007 at 10:35:08AM -0500, Tom Lane wrote:
>> SELECT EXTRACT(EPOCH FROM MAX(mydate)) FROM myTable

> Is using casts for the same purpose deprecated?

> 	SELECT current_date::timestamp::abstime::int4;

Well, type abstime is deprecated --- it's got a Y2038 problem.

			regards, tom lane



^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* Re: EPOCH TIMESTAMP Conversion Problem
  2007-11-07 10:37 EPOCH TIMESTAMP Conversion Problem Amitanand Chikorde <amit99rs@gmail.com>
  2007-11-07 15:35 ` Re: EPOCH TIMESTAMP Conversion Problem Tom Lane <tgl@sss.pgh.pa.us>
  2008-01-01 14:28   ` Re: EPOCH TIMESTAMP Conversion Problem Louis-David Mitterrand <vindex+lists-pgsql-sql@apartia.org>
@ 2008-01-01 19:32     ` Michael Glaesemann <grzm@seespotcode.net>
  1 sibling, 0 replies; 5+ messages in thread

From: Michael Glaesemann @ 2008-01-01 19:32 UTC (permalink / raw)
  To: Louis-David Mitterrand <vindex+lists-pgsql-sql@apartia.org>; +Cc: pgsql-sql


On Jan 1, 2008, at 9:28 , Louis-David Mitterrand wrote:

> On Wed, Nov 07, 2007 at 10:35:08AM -0500, Tom Lane wrote:
>> "Amitanand Chikorde" <amit99rs@gmail.com> writes:
>>> I want to convert MAX(mydate) from myTable to Epoch.
>>
>> Do you mean
>> 	SELECT EXTRACT(EPOCH FROM MAX(mydate)) FROM myTable
>
> Is using casts for the same purpose deprecated?
>
> 	SELECT current_date::timestamp::abstime::int4;

EXTRACT is SQL-standard syntax which appeals to some people. The ::  
casting syntax is a Postgres extension. And from the docs:

http://www.postgresql.org/docs/8.2/static/datatype-datetime.html

>  The types abstime  and reltime are lower precision types which are  
> used internally. You are discouraged from using these types in new  
> applications and are encouraged to move any old ones over when  
> appropriate. Any or all of these internal types might disappear in  
> a future release.


Michael Glaesemann
grzm seespotcode net





^ permalink  raw  reply  [nested|flat] 5+ messages in thread


end of thread, other threads:[~2008-01-01 19:32 UTC | newest]

Thread overview: 5+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2007-11-07 10:37 EPOCH TIMESTAMP Conversion Problem Amitanand Chikorde <amit99rs@gmail.com>
2007-11-07 15:35 ` Tom Lane <tgl@sss.pgh.pa.us>
2008-01-01 14:28   ` Louis-David Mitterrand <vindex+lists-pgsql-sql@apartia.org>
2008-01-01 19:03     ` Tom Lane <tgl@sss.pgh.pa.us>
2008-01-01 19:32     ` Michael Glaesemann <grzm@seespotcode.net>

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