Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re: select * and bind_cols considered harmful

by perrin (Chancellor)
on Nov 22, 2002 at 15:41 UTC ( [id://215130]=note: print w/replies, xml ) Need Help??


in reply to select * and bind_cols considered harmful
in thread Perl Programming guidelines/rules

Sorry, but I'm flabbergasted that anyone would ever use "select *" in a real program! That is the bug waiting to happen, not bind_cols.

I think typing out the list of lexical variables is worth the extra speed. There is some data on the speed difference in Tim Bunce's talk.

Of course, if speed makes no difference in your application then use whatever you like.

Replies are listed 'Best First'.
Re: Re: select * and bind_cols considered harmful
by blssu (Pilgrim) on Nov 22, 2002 at 18:56 UTC

    I'd categorize them as different kinds of bugs. The select * with fetchrow_hashref can lead to performance problems, but the bind_cols can completely break things.

    During code reviews I tell people to select explicit columns and use fetchrow_hashref. I know people are sometimes going to break standards and ignore my advice. There are three options I know of: (1) give them standards that will probably keep working even if not perfectly followed, (2) audit all code for compliance, (3) fire people who write bad code.

    Option (1) is my pragmatic choice. What's yours?

      Easy, it's nothing personal. Select * with fetchrow_hashref will break in confusing ways if a column name is changed, but will survive columns being added. Of course performance will get progressively worse as columns get added even if they aren't being used. Regardless, select * is obviously a bad practice and fetchrow_hashref is just a band-aid that hides some of the badness. The DBAs at most jobs I've had would have hung me from the rafters if I used select * in production code.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://215130]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (4)
As of 2024-04-20 06:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found