Re: [SQL] calculated expressions and index use

2003-01-31 Thread Tom Lane
Pavel Hlavnicka <[EMAIL PROTECTED]> writes: > I use 7.2.1. :( 7.2 certainly will fold "'now'::timestamp - '1 hour'::interval" to a timestamp constant. This could be a datatype compatibility issue (is created_at the same type? in particular, with/without time zone?) or it could be a selectivity i

Re: [SQL] calculated expressions and index use

2003-01-31 Thread Pavel Hlavnicka
Yes, you are right. It was an issue reated to the type compatibility. My braindead script created tables with 'datetime' types, what is 'timestamp without time zone' after I switched to 'timestamp', all works fine. Thanks a loc, the fact, you ensured me, that the constant expression should be

Re: [SQL] calculated expressions and index use

2003-01-31 Thread Pavel Hlavnicka
I use 7.2.1. :( Do you thing my considerations on constant vs. expression are correct? I tried different syntax, no success. Thanks Pavel Tom Lane wrote: Pavel Hlavnicka <[EMAIL PROTECTED]> writes: select * from foo where created_at >= 'now'::timestamp - '1 hour'::interval; My table is i

Re: [SQL] calculated expressions and index use

2003-01-30 Thread Tom Lane
Pavel Hlavnicka <[EMAIL PROTECTED]> writes: > select * from foo > where created_at >= 'now'::timestamp - '1 hour'::interval; > My table is indexed on created_at field. The query above doesn't use it, What's your PG version? In 7.2 and later that expression will be folded to a constant.

Re: [SQL] calculated expressions and index use

2003-01-30 Thread Arjen van der Meijden
A very dirty work around could be: select * from foo where created+at >= (select now() - '1 hour'::interval); Or perhaps this already works: select * from foo where created+at >= (now() - '1 hour'::interval); Pavel Hlavnicka wrote: Hi all, I use simple sql statement like this select * from foo

[SQL] calculated expressions and index use

2003-01-30 Thread Pavel Hlavnicka
Hi all, I use simple sql statement like this select * from foo where created_at >= 'now'::timestamp - '1 hour'::interval; My table is indexed on created_at field. The query above doesn't use it, but if I use select * from foo where created_at >= 'now' the index is used. It looks like if the