From: Nicola Musatti (Nicola.Musatti_at_[hidden])
Date: 2006-10-07 04:09:14
Jeremy Day wrote:
> On 10/6/06, james.jones_at_[hidden] <james.jones_at_[hidden]>
>> Surely you mean "... NOT using select *..."? I've always considered it a
>> best practice not to use select * in any production code. Is there another
>> perspective on this?
> It is my understanding that "select *" is generally less efficient than
> specifying the fields to select. Not to mention that if you are relying on
> select * to return fields in a specific order, and that order changes,
> you're in for some hard to find bugs.
I think that the choice depends on what you are doing. In an
object-relational mapping with a static, typesafe representation I would
express explicitly all fields in my query, so that any mismatch between
the current structure of the database and my code will cause my queries
to fail immediately.
On the other hand if I'm using a dynamic representation that only relies
on a limited subset of the fields involved in the query I'd use '*' so
as to limit the conditions that could break my code. In similar cases I
wouldn't rely on field order but rather on matching by name.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk