Re: [SQL] subtract a day from the NOW function

2007-06-08 Thread Campbell, Lance
ect: Re: [SQL] subtract a day from the NOW function --- "Campbell, Lance" <[EMAIL PROTECTED]> escreveu: > Table > > Field "some_timestamp" is a timestamp. > > > > In a "WHERE" statement I need to compare a timestamp > field in a table >

Re: [SQL] subtract a day from the NOW function

2007-06-07 Thread Tom Lane
Steve Crawford <[EMAIL PROTECTED]> writes: > But PG doesn't follow the same rules in subtracting timestamptz values > so operations involving timestamps and intervals are (sometimes) not > reversible: Yeah. timestamp_mi is performing a justify_hours call, which it should not, but removing that ca

Re: [SQL] subtract a day from the NOW function

2007-06-07 Thread Michael Glaesemann
On Jun 7, 2007, at 16:07 , Steve Crawford wrote: On 8.2 I'm seeing an adjustment if the DST adjustment includes units of "day" or greater (ie. '1 day' and '1 day 01:00' get adjusted but '24 hours' and '25 hours' do not). But PG doesn't follow the same rules in subtracting timestamptz values

Re: [SQL] subtract a day from the NOW function

2007-06-07 Thread Michael Glaesemann
On Jun 7, 2007, at 15:38 , Fernando Hevia wrote: Why not? I'm curious if has anything to do with performance or just style? Not style. Maybe performance because there's fewer function calls, but primarily correctness. By using to_char you no longer have a date— you have a text value—and a

Re: [SQL] subtract a day from the NOW function

2007-06-07 Thread Osvaldo Kussama
--- "Campbell, Lance" <[EMAIL PROTECTED]> escreveu: > Table > > Field "some_timestamp" is a timestamp. > > > > In a "WHERE" statement I need to compare a timestamp > field in a table > "some_timestamp" to now() - one day. > > > > Example: > > > > SELECT some_timestamp WHERE to_char(s

Re: [SQL] subtract a day from the NOW function

2007-06-07 Thread Steve Crawford
Michael Glaesemann wrote: > > On Jun 7, 2007, at 13:58 , Steve Crawford wrote: > >> Beware in the "or something like that category" that PostgreSQL >> considers "1 day" to be "24 hours" > > Actually, recent versions of PostgreSQL take into account daylight > saving time in accordance with the cu

Re: [SQL] subtract a day from the NOW function

2007-06-07 Thread Fernando Hevia
>> B) SELECT * FROM some_table WHERE to_char(some_timestamp, >> 'MMDD') > >> to_char((now() - interval '1 day'), 'MMDD'); > >I'd never use to_char to compare dates. The built-in comparison >operators work just fine. > Why not? I'm curious if has anything to do with performance or just

Re: [SQL] subtract a day from the NOW function

2007-06-07 Thread Michael Glaesemann
On Jun 7, 2007, at 13:58 , Steve Crawford wrote: Beware in the "or something like that category" that PostgreSQL considers "1 day" to be "24 hours" Actually, recent versions of PostgreSQL take into account daylight saving time in accordance with the current PostgreSQL time zone setting, s

Re: [SQL] subtract a day from the NOW function

2007-06-07 Thread Steve Crawford
Scott Marlowe wrote: > Campbell, Lance wrote: >> Michael, >> So based on your feedback would it be better to do option A or B below? >> >> 1) I have a timestamp field, "some_timestamp", in table "some_table". >> 2) I want to compare field "some_timestamp" to the current date - 1 day. >> I need to i

Re: [SQL] subtract a day from the NOW function

2007-06-07 Thread Michael Glaesemann
[Please don't top-post. It makes the discussion difficult to follow.] On Jun 7, 2007, at 12:49 , Campbell, Lance wrote: 1) I have a timestamp field, "some_timestamp", in table "some_table". 2) I want to compare field "some_timestamp" to the current date - 1 day. I need to ignore hours, minut

Re: [SQL] subtract a day from the NOW function

2007-06-07 Thread Scott Marlowe
Campbell, Lance wrote: Michael, So based on your feedback would it be better to do option A or B below? 1) I have a timestamp field, "some_timestamp", in table "some_table". 2) I want to compare field "some_timestamp" to the current date - 1 day. I need to ignore hours, minutes and seconds.

Re: [SQL] subtract a day from the NOW function

2007-06-07 Thread Campbell, Lance
el Glaesemann [mailto:[EMAIL PROTECTED] Sent: Thursday, June 07, 2007 12:27 PM To: Campbell, Lance Cc: pgsql-sql@postgresql.org Subject: Re: [SQL] subtract a day from the NOW function > From: [EMAIL PROTECTED] [mailto:pgsql-sql- > [EMAIL PROTECTED] On Behalf Of Campbell, Lance > Sent: Thur

Re: [SQL] subtract a day from the NOW function

2007-06-07 Thread Michael Glaesemann
From: [EMAIL PROTECTED] [mailto:pgsql-sql- [EMAIL PROTECTED] On Behalf Of Campbell, Lance Sent: Thursday, June 07, 2007 11:09 AM To: pgsql-sql@postgresql.org Subject: [SQL] subtract a day from the NOW function SELECT some_timestamp WHERE to_char(some_timestamp, ‘MMDD’) > (to_char(

Re: [SQL] subtract a day from the NOW function

2007-06-07 Thread Campbell, Lance
, 2007 11:37 AM To: pgsql-sql@postgresql.org Subject: Re: [SQL] subtract a day from the NOW function I just figured it out. The solution is: select to_char((now() - interval '1 day'), 'MMDD'); Thanks, Lance Campbell Project Manager/Software Architect We

Re: [SQL] subtract a day from the NOW function

2007-06-07 Thread Campbell, Lance
webservices.uiuc.edu From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Campbell, Lance Sent: Thursday, June 07, 2007 11:09 AM To: pgsql-sql@postgresql.org Subject: [SQL] subtract a day from the NOW function Table Field "some_timestamp" is a timestamp. In a "

[SQL] subtract a day from the NOW function

2007-06-07 Thread Campbell, Lance
Table Field "some_timestamp" is a timestamp. In a "WHERE" statement I need to compare a timestamp field in a table "some_timestamp" to now() - one day. Example: SELECT some_timestamp WHERE to_char(some_timestamp, 'MMDD') > (to_char(now(), 'MMDD') - 1 day); The statement "to