public inbox for [email protected]  
help / color / mirror / Atom feed
Suggestion for Date/Time Functions Section
3+ messages / 3 participants
[nested] [flat]

* Suggestion for Date/Time Functions Section
@ 2005-08-20 04:59 CSN <[email protected]>
  2005-08-20 05:42 ` Re: Suggestion for Date/Time Functions Section Michael Glaesemann <[email protected]>
  2005-08-20 05:44 ` Re: [GENERAL] Suggestion for Date/Time Functions Section Stephan Szabo <[email protected]>
  0 siblings, 2 replies; 3+ messages in thread

From: CSN @ 2005-08-20 04:59 UTC (permalink / raw)
  To: pgsql-docs; [email protected]

Hi,

I suggestion for the date/time functions in the docs:
http://www.postgresql.org/docs/8.0/interactive/functions-datetime.html

I was trying to figure out how to do:
update table set next=now() + interval 'table.period
seconds';

I tried subqueries, the concat operator, and anything
else I could think of until I rediscovered the page on
the various ways to cast. Perhaps mix up the examples
in the docs so other ways to do date arithmetic (and
that allow expressions, fields, etc.) are obvious:

date '2001-09-28' + cast((7+7)||' seconds' as
interval);
date '2001-09-28' + ((7+7)||' seconds')::interval);
etc.

Or am I missing an easier way to do date arithmetic
using a table's fields as part of the equation? (I
think mysql has date_add(...), date_subtract(...),
etc.

CSN

__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 



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

* Re: Suggestion for Date/Time Functions Section
  2005-08-20 04:59 Suggestion for Date/Time Functions Section CSN <[email protected]>
@ 2005-08-20 05:42 ` Michael Glaesemann <[email protected]>
  1 sibling, 0 replies; 3+ messages in thread

From: Michael Glaesemann @ 2005-08-20 05:42 UTC (permalink / raw)
  To: CSN <[email protected]>; +Cc: pgsql-docs; [email protected]


On Aug 20, 2005, at 1:59 PM, CSN wrote:

> I was trying to figure out how to do:
> update table set next=now() + interval 'table.period
> seconds';

create table foo (
     foo_id serial not null unique
     , foo_int integer not null
     , foo_timestamp timestamp(0) with time zone not null
) without oids;

insert into foo (foo_int, foo_timestamp) values (10, current_timestamp);
insert into foo (foo_int, foo_timestamp) values (20,  
current_timestamp + interval '20 seconds');
insert into foo (foo_int, foo_timestamp) values (30,  
current_timestamp + interval '30 seconds');
insert into foo (foo_int, foo_timestamp) values (40,  
current_timestamp + interval '40 seconds');

test=# select foo_id, foo_int, foo_timestamp from foo;
foo_id | foo_int |     foo_timestamp
--------+---------+------------------------
       1 |      10 | 2005-08-20 14:39:14+09
       2 |      20 | 2005-08-20 14:39:34+09
       3 |      30 | 2005-08-20 14:39:44+09
       4 |      40 | 2005-08-20 14:39:54+09
(4 rows)

test=# update foo set foo_timestamp = current_timestamp + foo_int *  
interval '1 second';
UPDATE 4
test=# select foo_id, foo_int, foo_timestamp from foo;
foo_id | foo_int |     foo_timestamp
--------+---------+------------------------
       1 |      10 | 2005-08-20 14:39:58+09
       2 |      20 | 2005-08-20 14:40:08+09
       3 |      30 | 2005-08-20 14:40:18+09
       4 |      40 | 2005-08-20 14:40:28+09
(4 rows)

Is that what you want?


Michael Glaesemann
grzm myrealbox com





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

* Re: [GENERAL] Suggestion for Date/Time Functions Section
  2005-08-20 04:59 Suggestion for Date/Time Functions Section CSN <[email protected]>
@ 2005-08-20 05:44 ` Stephan Szabo <[email protected]>
  1 sibling, 0 replies; 3+ messages in thread

From: Stephan Szabo @ 2005-08-20 05:44 UTC (permalink / raw)
  To: CSN <[email protected]>; +Cc: pgsql-docs; [email protected]


On Fri, 19 Aug 2005, CSN wrote:

> Hi,
>
> I suggestion for the date/time functions in the docs:
> http://www.postgresql.org/docs/8.0/interactive/functions-datetime.html
>
> I was trying to figure out how to do:
> update table set next=now() + interval 'table.period
> seconds';
>
> I tried subqueries, the concat operator, and anything
> else I could think of until I rediscovered the page on
> the various ways to cast. Perhaps mix up the examples
> in the docs so other ways to do date arithmetic (and
> that allow expressions, fields, etc.) are obvious:
>
> date '2001-09-28' + cast((7+7)||' seconds' as
> interval);

I'd suggest something like
 date '2001-09-28' + (7+7) * interval '1 second';
instead of using text concatenation.





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


end of thread, other threads:[~2005-08-20 05:44 UTC | newest]

Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2005-08-20 04:59 Suggestion for Date/Time Functions Section CSN <[email protected]>
2005-08-20 05:42 ` Michael Glaesemann <[email protected]>
2005-08-20 05:44 ` Stephan Szabo <[email protected]>

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox