pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
time
10+ messages / 5 participants
[nested] [flat]

* time
@ 2005-11-10 15:03 Judith Altamirano Figueroa <jaltamirano@correolux.com.mx>
  2005-11-10 15:16 ` Re: time Judith Altamirano Figueroa <jaltamirano@correolux.com.mx>
  2005-11-10 18:11 ` Re: time Rod Taylor <pg@rbt.ca>
  0 siblings, 2 replies; 10+ messages in thread

From: Judith Altamirano Figueroa @ 2005-11-10 15:03 UTC (permalink / raw)
  To: pgsql-sql

Hello everybody!!!, I'd like to know if there another way to get the
time from a timestamp type, because in earliest versions I just get the
time like time(fecha) and now this returns an error, thanks in
advanced!!!!!!!

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

* Re: time
  2005-11-10 15:03 time Judith Altamirano Figueroa <jaltamirano@correolux.com.mx>
@ 2005-11-10 15:16 ` Judith Altamirano Figueroa <jaltamirano@correolux.com.mx>
  1 sibling, 0 replies; 10+ messages in thread

From: Judith Altamirano Figueroa @ 2005-11-10 15:16 UTC (permalink / raw)
  To: pgsql-sql



> Hello everybody!!!, I'd like to know if there another way to get the
> time from a timestamp type, because in earliest versions I just get
> the time like time(fecha) and now
> this returns an error, thanks in advanced!!!!!!!

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

* Re: time
  2005-11-10 15:03 time Judith Altamirano Figueroa <jaltamirano@correolux.com.mx>
@ 2005-11-10 18:11 ` Rod Taylor <pg@rbt.ca>
  2005-11-10 18:21   ` Re: time Michael Fuhr <mike@fuhr.org>
  1 sibling, 1 reply; 10+ messages in thread

From: Rod Taylor @ 2005-11-10 18:11 UTC (permalink / raw)
  To: Judith Altamirano Figueroa <jaltamirano@correolux.com.mx>; +Cc: pgsql-sql

On Thu, 2005-11-10 at 09:03 -0600, Judith Altamirano Figueroa wrote:
> Hello everybody!!!, I'd like to know if there another way to get the
> time from a timestamp type, because in earliest versions I just get
> the time like time(fecha) and now this returns an error, thanks in
> advanced!!!!!!!

rbt=# select cast(now() - date_trunc('day', now()) as time);
      time
-----------------
 13:10:42.495579
(1 row)

-- 




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

* Re: time
  2005-11-10 15:03 time Judith Altamirano Figueroa <jaltamirano@correolux.com.mx>
  2005-11-10 18:11 ` Re: time Rod Taylor <pg@rbt.ca>
@ 2005-11-10 18:21   ` Michael Fuhr <mike@fuhr.org>
  2005-11-10 18:27     ` Re: time Rod Taylor <pg@rbt.ca>
  2005-11-10 18:38     ` Re: time Michael Fuhr <mike@fuhr.org>
  2005-11-10 19:13     ` Re: time Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 3 replies; 10+ messages in thread

From: Michael Fuhr @ 2005-11-10 18:21 UTC (permalink / raw)
  To: Rod Taylor <pg@rbt.ca>; +Cc: Judith Altamirano Figueroa <jaltamirano@correolux.com.mx>; pgsql-sql

On Thu, Nov 10, 2005 at 01:11:27PM -0500, Rod Taylor wrote:
> rbt=# select cast(now() - date_trunc('day', now()) as time);
>       time
> -----------------
>  13:10:42.495579
> (1 row)

Am I missing something?  Is there a reason not to simply cast the
timestamp value to time?

test=> select cast(now() - date_trunc('day', now()) as time);
        time         
---------------------
 11:19:19.8921250105
(1 row)

test=> select now()::time;
       now       
-----------------
 11:19:19.892125
(1 row)

test=> select cast(now() as time);
       now       
-----------------
 11:19:19.892125
(1 row)

-- 
Michael Fuhr



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

* Re: time
  2005-11-10 15:03 time Judith Altamirano Figueroa <jaltamirano@correolux.com.mx>
  2005-11-10 18:11 ` Re: time Rod Taylor <pg@rbt.ca>
  2005-11-10 18:21   ` Re: time Michael Fuhr <mike@fuhr.org>
@ 2005-11-10 18:27     ` Rod Taylor <pg@rbt.ca>
  2 siblings, 0 replies; 10+ messages in thread

From: Rod Taylor @ 2005-11-10 18:27 UTC (permalink / raw)
  To: Michael Fuhr <mike@fuhr.org>; +Cc: Judith Altamirano Figueroa <jaltamirano@correolux.com.mx>; pgsql-sql

On Thu, 2005-11-10 at 11:21 -0700, Michael Fuhr wrote:
> On Thu, Nov 10, 2005 at 01:11:27PM -0500, Rod Taylor wrote:
> > rbt=# select cast(now() - date_trunc('day', now()) as time);
> >       time
> > -----------------
> >  13:10:42.495579
> > (1 row)
> 
> Am I missing something?  Is there a reason not to simply cast the
> timestamp value to time?

Nope. I had thought that the question came up because a straight cast
didn't work so I gave the first work around I thought of.
-- 




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

* Re: time
  2005-11-10 15:03 time Judith Altamirano Figueroa <jaltamirano@correolux.com.mx>
  2005-11-10 18:11 ` Re: time Rod Taylor <pg@rbt.ca>
  2005-11-10 18:21   ` Re: time Michael Fuhr <mike@fuhr.org>
@ 2005-11-10 18:38     ` Michael Fuhr <mike@fuhr.org>
  2 siblings, 0 replies; 10+ messages in thread

From: Michael Fuhr @ 2005-11-10 18:38 UTC (permalink / raw)
  To: Judith Altamirano Figueroa <jaltamirano@correolux.com.mx>; +Cc: pgsql-sql

[Please copy the mailing list on replies.]

On Thu, Nov 10, 2005 at 12:24:17PM -0600, Judith Altamirano Figueroa wrote:
> excuse me and how can I just get the hour, minute and second

The time type takes an optional precision:

test=> select now()::time;
       now       
-----------------
 11:36:34.124678
(1 row)

test=> select now()::time(0);
   now    
----------
 11:36:34
(1 row)

test=> select now()::time(2);
     now     
-------------
 11:36:34.12
(1 row)

-- 
Michael Fuhr



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

* Re: time
  2005-11-10 15:03 time Judith Altamirano Figueroa <jaltamirano@correolux.com.mx>
  2005-11-10 18:11 ` Re: time Rod Taylor <pg@rbt.ca>
  2005-11-10 18:21   ` Re: time Michael Fuhr <mike@fuhr.org>
@ 2005-11-10 19:13     ` Tom Lane <tgl@sss.pgh.pa.us>
  2005-11-10 19:22       ` Re: time Michael Fuhr <mike@fuhr.org>
  2005-11-10 19:29       ` Re: time Tadej Kanizar <Tadej.Kanizar@sagit-server.com>
  2 siblings, 2 replies; 10+ messages in thread

From: Tom Lane @ 2005-11-10 19:13 UTC (permalink / raw)
  To: Michael Fuhr <mike@fuhr.org>; +Cc: Rod Taylor <pg@rbt.ca>; Judith Altamirano Figueroa <jaltamirano@correolux.com.mx>; pgsql-sql

Michael Fuhr <mike@fuhr.org> writes:
> Am I missing something?  Is there a reason not to simply cast the
> timestamp value to time?

> test=> select now()::time;
>        now       
> -----------------
>  11:19:19.892125
> (1 row)

> test=> select cast(now() as time);
>        now       
> -----------------
>  11:19:19.892125
> (1 row)

I think the OP was trying to use the functional cast syntax
	time(now())
which worked long ago, but has not since we added the
SQL-spec time precision syntax.

			regards, tom lane



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

* Re: time
  2005-11-10 15:03 time Judith Altamirano Figueroa <jaltamirano@correolux.com.mx>
  2005-11-10 18:11 ` Re: time Rod Taylor <pg@rbt.ca>
  2005-11-10 18:21   ` Re: time Michael Fuhr <mike@fuhr.org>
  2005-11-10 19:13     ` Re: time Tom Lane <tgl@sss.pgh.pa.us>
@ 2005-11-10 19:22       ` Michael Fuhr <mike@fuhr.org>
  1 sibling, 0 replies; 10+ messages in thread

From: Michael Fuhr @ 2005-11-10 19:22 UTC (permalink / raw)
  To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: Rod Taylor <pg@rbt.ca>; Judith Altamirano Figueroa <jaltamirano@correolux.com.mx>; pgsql-sql

On Thu, Nov 10, 2005 at 02:13:43PM -0500, Tom Lane wrote:
> Michael Fuhr <mike@fuhr.org> writes:
> > Am I missing something?  Is there a reason not to simply cast the
> > timestamp value to time?
> 
> I think the OP was trying to use the functional cast syntax
> 	time(now())
> which worked long ago, but has not since we added the
> SQL-spec time precision syntax.

I was referring to the expression that Rod Taylor posted, wondering
if there was some subtlety I was missing or if Rod simply didn't
think of the simpler solution (Rod responded indicating the latter).

-- 
Michael Fuhr



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

* Re: time
  2005-11-10 15:03 time Judith Altamirano Figueroa <jaltamirano@correolux.com.mx>
  2005-11-10 18:11 ` Re: time Rod Taylor <pg@rbt.ca>
  2005-11-10 18:21   ` Re: time Michael Fuhr <mike@fuhr.org>
  2005-11-10 19:13     ` Re: time Tom Lane <tgl@sss.pgh.pa.us>
@ 2005-11-10 19:29       ` Tadej Kanizar <Tadej.Kanizar@sagit-server.com>
  2005-11-10 21:30         ` Re: time Michael Fuhr <mike@fuhr.org>
  1 sibling, 1 reply; 10+ messages in thread

From: Tadej Kanizar @ 2005-11-10 19:29 UTC (permalink / raw)
  To: pgsql-sql

So I don't open a new thread.. 
I have a table with a column of type TIMESTAMP.
In output, I need to format it.. what's the best way to do it?
So, for instance, how could I format it so that it would output as YY-MM-DD
HH:MM?

Regards,
Tadej

-----Original Message-----
From: pgsql-sql-owner@postgresql.org [mailto:pgsql-sql-owner@postgresql.org]
On Behalf Of Tom Lane
Sent: 10. november 2005 20:14
To: Michael Fuhr
Cc: Rod Taylor; Judith Altamirano Figueroa; pgsql-sql@postgresql.org
Subject: Re: [SQL] time 

Michael Fuhr <mike@fuhr.org> writes:
> Am I missing something?  Is there a reason not to simply cast the
> timestamp value to time?

> test=> select now()::time;
>        now       
> -----------------
>  11:19:19.892125
> (1 row)

> test=> select cast(now() as time);
>        now       
> -----------------
>  11:19:19.892125
> (1 row)

I think the OP was trying to use the functional cast syntax
	time(now())
which worked long ago, but has not since we added the
SQL-spec time precision syntax.

			regards, tom lane

---------------------------(end of broadcast)---------------------------
TIP 4: Have you searched our list archives?

               http://archives.postgresql.org




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

* Re: time
  2005-11-10 15:03 time Judith Altamirano Figueroa <jaltamirano@correolux.com.mx>
  2005-11-10 18:11 ` Re: time Rod Taylor <pg@rbt.ca>
  2005-11-10 18:21   ` Re: time Michael Fuhr <mike@fuhr.org>
  2005-11-10 19:13     ` Re: time Tom Lane <tgl@sss.pgh.pa.us>
  2005-11-10 19:29       ` Re: time Tadej Kanizar <Tadej.Kanizar@sagit-server.com>
@ 2005-11-10 21:30         ` Michael Fuhr <mike@fuhr.org>
  0 siblings, 0 replies; 10+ messages in thread

From: Michael Fuhr @ 2005-11-10 21:30 UTC (permalink / raw)
  To: Tadej Kanizar <Tadej.Kanizar@sagit-server.com>; +Cc: pgsql-sql

On Thu, Nov 10, 2005 at 08:29:07PM +0100, Tadej Kanizar wrote:
> I have a table with a column of type TIMESTAMP.
> In output, I need to format it.. what's the best way to do it?
> So, for instance, how could I format it so that it would output as YY-MM-DD
> HH:MM?

See to_char() in the "Data Type Formatting Functions" section
of the "Functions and Operators" chapter in the documentation.

http://www.postgresql.org/docs/8.0/interactive/functions-formatting.html

-- 
Michael Fuhr



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


end of thread, other threads:[~2005-11-10 21:30 UTC | newest]

Thread overview: 10+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2005-11-10 15:03 time Judith Altamirano Figueroa <jaltamirano@correolux.com.mx>
2005-11-10 15:16 ` Judith Altamirano Figueroa <jaltamirano@correolux.com.mx>
2005-11-10 18:11 ` Rod Taylor <pg@rbt.ca>
2005-11-10 18:21   ` Michael Fuhr <mike@fuhr.org>
2005-11-10 18:27     ` Rod Taylor <pg@rbt.ca>
2005-11-10 18:38     ` Michael Fuhr <mike@fuhr.org>
2005-11-10 19:13     ` Tom Lane <tgl@sss.pgh.pa.us>
2005-11-10 19:22       ` Michael Fuhr <mike@fuhr.org>
2005-11-10 19:29       ` Tadej Kanizar <Tadej.Kanizar@sagit-server.com>
2005-11-10 21:30         ` Michael Fuhr <mike@fuhr.org>

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