![]() | |
![]() |
| | Thread Tools | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
-------------------------------------------------------------------------- ----------------- Patrick Fiche email : patrick.fiche (AT) aqsacom (DOT) com tél : 01 69 29 36 18 -------------------------------------------------------------------------- ----------------- |
gsql-general-owner (AT) postgresql (DOT) org]On Behalf Of Scott Nixon
#3
| |||
| |||
|
|
Have a try at this syntax SELECT number FROM procedures WHERE date + CAST( numdays || ' days' AS interval ) <= CURRENT_TIMESTAMP; Patrick |
#4
| |||
| |||
|
|
Have a try at this syntax SELECT number FROM procedures WHERE date + CAST( numdays || ' days' AS interval ) <= CURRENT_TIMESTAMP; |
#5
| |||
| |||
|
|
On Mon, 22 Nov 2004 15:12:26 +0100, Patrick Fiche patrick.fiche (AT) aqsacom (DOT) com> wrote: Have a try at this syntax SELECT number FROM procedures WHERE date + CAST( numdays || ' days' AS interval ) <= CURRENT_TIMESTAMP; Just for the record you could write it like this too: SELECT number FROM procedures WHERE date + (numdays || ' days')::interval <= CURRENT_TIMESTAMP; |
#6
| |||
| |||
|
|
Just to add to the record, the mathematically sound way to write this query would be this: SELECT number FROM procedures WHERE date + numdays * interval '1 day' <= current_timestamp; |
|
Ian Barwick wrote: On Mon, 22 Nov 2004 15:12:26 +0100, Patrick Fiche patrick.fiche (AT) aqsacom (DOT) com> wrote: Have a try at this syntax SELECT number FROM procedures WHERE date + CAST( numdays || ' days' AS interval ) <= CURRENT_TIMESTAMP; Just for the record you could write it like this too: SELECT number FROM procedures WHERE date + (numdays || ' days')::interval <= CURRENT_TIMESTAMP; Just to add to the record, the mathematically sound way to write this query would be this: SELECT number FROM procedures WHERE date + numdays * interval '1 day' <= current_timestamp; -- Peter Eisentraut http://developer.postgresql.org/~petere/ |
#7
| |||
| |||
|
|
Am having some trouble with a query that worked in 7.0 but not in 7.3.....can't seem to figure out the syntax or find info about how to do this anywhere. SELECT number FROM procedures WHERE date + numdays <= CURRENT_TIMESTAMP; In 7.0 this works with no problem... |
#8
| |||
| |||
|
|
So I think what you probably *really* want is ... WHERE CAST(date AS date) + numdays <= CURRENT_DATE; |
|
Scott Nixon <snixon (AT) lssi (DOT) net> writes: Am having some trouble with a query that worked in 7.0 but not in 7.3.....can't seem to figure out the syntax or find info about how to do this anywhere. SELECT number FROM procedures WHERE date + numdays <= CURRENT_TIMESTAMP; In 7.0 this works with no problem... (Tries it...) The reason it worked in 7.0 was that 7.0 would implicitly down-convert the timestamp value to a value of type date, and then apply the date-plus-integer operator. The operator is still there, but later versions are less willing to apply information-losing type coercions implicitly. So the exact equivalent of what you were doing before is ... WHERE CAST(date AS date) + numdays <= CURRENT_TIMESTAMP; The comparison portion of this will require an up-conversion from date back to timestamp, which is inefficient and pointless (not to mention that it exposes you to daylight-savings-transition issues, because CURRENT_TIMESTAMP is timestamp with time zone). So I think what you probably *really* want is ... WHERE CAST(date AS date) + numdays <= CURRENT_DATE; which keeps both the addition and the comparison as simple date operations with no sub-day resolution and no timezone funnies. regards, tom lane -- |
![]() |
| Thread Tools | |
| Display Modes | |
| |