pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
timespan arithmetic
3+ messages / 2 participants
[nested] [flat]

* timespan arithmetic
@ 1999-07-26 23:00  David Rose <David.R.Rose@disney.com>
  0 siblings, 0 replies; 3+ messages in thread

From: David Rose @ 1999-07-26 23:00 UTC (permalink / raw)
  To: pgsql-sql

Hello.

I recently posted this question on pgsql-novice and received no
answer.  Undaunted, I'm trying again on pgsql-sql.  Perhaps someone
knows at least where to start looking for an answer to this problem.
It's not in the FAQ, and I couldn't find an answer in the mailing list
archives.

I have a table that includes a column of type timestamp.  I'd like to
formulate a query that returns, say, all rows no more than 24 hours
old, based on the timestamp.  Trial and error got me this far (and a
perusal of the mailing list archives confirmed it):

  SELECT * FROM table 
  WHERE loaded_time >= 'now'::timestamp - '1 days'::timespan
  ORDER BY loaded_time DESC;

This works fine in PostgreSQL 6.4.2.  However, another user of my
software, who has PostgreSQL 6.3.2, reports that he gets the following
error message:

  ERROR: There is no operator '-' for types 'timestamp' and 'timespan'
  You will either have to retype this query using an explicit cast, or you
  will have to define the operator using CREATE OPERATOR


So.  Is there a correct solution to this problem that works for all
versions of PostgreSQL--or at least, PostgreSQL versions 6.3.2 and
higher?  Barring that, is there at least a solution at all for 6.3.2,
which may or may not be different from the solution for 6.4.2 and
higher?

Many thanks.

David




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

* RE: [SQL] timespan arithmetic
@ 1999-07-26 23:16  Jackson, DeJuan <djackson@cpsgroup.com>
  0 siblings, 1 reply; 3+ messages in thread

From: Jackson, DeJuan @ 1999-07-26 23:16 UTC (permalink / raw)
  To: David Rose <David.R.Rose@disney.com>; pgsql-sql

I'm not certain this will work, but
try:
	SELECT * FROM table 
	  WHERE loaded_time::datetime >= now()::datetime - '1
days'::timespan
	  ORDER BY loaded_time DESC;


> -----Original Message-----
> From:	David Rose [SMTP:David.R.Rose@disney.com]
> Sent:	Monday, July 26, 1999 6:01 PM
> To:	pgsql-sql@postgreSQL.org
> Subject:	[SQL] timespan arithmetic
> 
> Hello.
> 
> I recently posted this question on pgsql-novice and received no
> answer.  Undaunted, I'm trying again on pgsql-sql.  Perhaps someone
> knows at least where to start looking for an answer to this problem.
> It's not in the FAQ, and I couldn't find an answer in the mailing list
> archives.
> 
> I have a table that includes a column of type timestamp.  I'd like to
> formulate a query that returns, say, all rows no more than 24 hours
> old, based on the timestamp.  Trial and error got me this far (and a
> perusal of the mailing list archives confirmed it):
> 
>   SELECT * FROM table 
>   WHERE loaded_time >= 'now'::timestamp - '1 days'::timespan
>   ORDER BY loaded_time DESC;
> 
> This works fine in PostgreSQL 6.4.2.  However, another user of my
> software, who has PostgreSQL 6.3.2, reports that he gets the following
> error message:
> 
>   ERROR: There is no operator '-' for types 'timestamp' and 'timespan'
>   You will either have to retype this query using an explicit cast, or you
>   will have to define the operator using CREATE OPERATOR
> 
> 
> So.  Is there a correct solution to this problem that works for all
> versions of PostgreSQL--or at least, PostgreSQL versions 6.3.2 and
> higher?  Barring that, is there at least a solution at all for 6.3.2,
> which may or may not be different from the solution for 6.4.2 and
> higher?
> 
> Many thanks.
> 
> David
> 



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

* RE: [SQL] timespan arithmetic
@ 1999-07-27 05:51  David Rose <David.R.Rose@disney.com>
  parent: Jackson, DeJuan <djackson@cpsgroup.com>
  0 siblings, 0 replies; 3+ messages in thread

From: David Rose @ 1999-07-27 05:51 UTC (permalink / raw)
  To: pgsql-sql

Jackson, DeJuan writes:
> I'm not certain this will work, but
> try:
> 	SELECT * FROM table 
> 	  WHERE loaded_time::datetime >= now()::datetime - '1
> days'::timespan
> 	  ORDER BY loaded_time DESC;

Excellent!  That did the trick.  Many thanks!

(I feel a little stupid for not thinking of trying 'datetime' by
myself--I was running into a dead end with 'reltime'.  Oh well.
Thanks!)

David




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


end of thread, other threads:[~1999-07-27 05:51 UTC | newest]

Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
1999-07-26 23:00 timespan arithmetic David Rose <David.R.Rose@disney.com>
1999-07-26 23:16 RE: [SQL] timespan arithmetic Jackson, DeJuan <djackson@cpsgroup.com>
1999-07-27 05:51 ` David Rose <David.R.Rose@disney.com>

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