4 ms·
Select * is something no one should be doing in real code. Select [list of columns] should the way to query and doing so you know exactly what columns are read
by albertopv 4y ago
Select * is something no one should be doing in real code.
Select [list of columns] should the way to query and doing so you know exactly what columns are read. That's one of the reasons I dislike ORM like hibernate.
I advocate the least surprises principle, select * or select !column are doors to surprises. What if someone add a geometry column with tons of data (real example happened to me)? You are going to read tons of data that probably you don't need.
- phplovesong 4y agoThe query itself does not matter. If i delete/rename a column the app WILL break no matter how much i would follow best practices. I dont see `select !name from users` any worse than `select name from users`. In both scenarios the app will break if the name column is renamed/deleted.
- beefield 4y agoTo me the biggest thing against select * is readability. Basically you are obfuscating what you are doing and getting from the database. In trivial queries it does not matter, but when you read more complex procedures, it starts to be a bit annoying.
- diogofranco 4y agoBut delete/rename columns are not the only operations, nor the most common. Adding columns is the most common, and there only one of those options breaks
- rsaarsoo 4y agoI think there are pros and cons to both approaches: - Explicitly spelling out the column names has the advantage that you can search your code base for that name and see where it's used. - When declaring a view which filters the rows in a table, using SELECT * would simplify maintenance, as you wouldn't need to update the view when new columns get added to the table.