On Sat, Dec 11, 2004 at 03:32:13PM +0100, Steinar H. Gunderson wrote:
> On Sat, Dec 11, 2004 at 03:17:13PM +0100, Tomas Skäre wrote:
> > select c.* from cjm_object c
> > inner join
> > (select max(timestamp) as timestamp,objectid,field from cjm_object
> > group by objectid,field) t
> > using(timestamp,objectid,field)
> > where 1=1 and data is not null
> > order by objectid,field;
>
> Usually, SELECT max(field) FROM table is better written in PostgreSQL as
> SELECT field FROM table ORDER field DESC LIMIT 1.
>
> I don't see the point of "where 1=1", though...
I've seen that in generated queries. The generating program uses
"WHERE 1=1" to simplify the addition of other conditions: instead
of checking if it needs to add a WHERE and putting ANDs in the right
places, it simply appends subsequent conditions with " AND condition".
--
Michael Fuhr
http://www.fuhr.org/~mfuhr/
In response to
pgsql-performance by date
| Next: | From: Alvaro Nunes Melo | Date: 2004-12-11 17:01:24 |
| Subject: Very different index usage on similar tables |
| Previous: | From: Mike Rylander | Date: 2004-12-11 14:37:15 |
| Subject: Re: LIMIT causes SEQSCAN in subselect |
pgsql-sql by date
| Next: | From: Rod Taylor | Date: 2004-12-11 16:35:01 |
| Subject: Re: replacing mysql enum |
| Previous: | From: Stephan Szabo | Date: 2004-12-11 15:47:51 |
| Subject: Re: replacing mysql enum |
pgsql-general by date
| Next: | From: Michael Fuhr | Date: 2004-12-11 16:33:32 |
| Subject: Re: Checking inequality |
| Previous: | From: Ioannis Theoharis | Date: 2004-12-11 15:27:02 |
| Subject: Clustering in the presence of hierarchies (fwd) |