DEV Community

Shariful Ehasan
Shariful Ehasan

Posted on

2 2 2 1

Do You Use SELECT * or Explicit Columns in Production Queries?

SQL gives us the handy SELECT * to quickly grab all columns from a table but should we really use it in production?

Some developers love the speed and convenience of SELECT *, especially during prototyping or when working with wide tables. Others argue it leads to performance issues, tight coupling, and unreadable queries and insist on selecting only the columns you actually need.

Quick and dirty
SELECT * FROM users;
More controlled
SELECT id, name, email FROM users;
  • Do you prefer SELECT * or writing explicit column names in your queries?

  • Have you ever run into a real world issue because of SELECT *?

  • What do you think is the best practice, and why?

Top comments (8)

Collapse
 
nathan_tarbert profile image
Nathan Tarbert

pretty cool seeing folks split over this - i used to be all about the fast way but honestly, the small mess adds up over time. ever notice if one tiny shortcut ever cost you way more than you expected later?

Collapse
 
0xw3ston profile image
Youssef El Idrissi

I had this on my first ever project, well it wasn't that tiny of a mistake.

So I did choose to work with an API style architecture, meaning I just split the code into models, controllers, routes.

The issue was that after a lot of work I realized that there was a lot of technical debt in terms of the sneaky grow of responsibilities of each "module" and realized I should have worked with a Layered Architecture instead.

Collapse
 
thunder6230 profile image
thunder6230

Always best to take only the columns you need. You can save a lot unnecessary data traffic. Not on a small local db but if you use cloud sqlek they have resource limits and makes the wonder very noticable!

Collapse
 
marylewisff profile image
MaryLewis

I found this discussion really insightful because it highlights a balance between convenience and performance that many developers wrestle with daily. Using SELECT * can be tempting for quick tests, but explicitly naming columns definitely makes production queries cleaner and more efficient, which ultimately helps maintainability and speeds up response times. It reminds me of how Magis TV Gratis lets you pick exactly what you want to watch instead of overwhelming you with everything at once—both approaches improve the user experience by being more deliberate and focused. What’s your go-to approach when writing production queries—do you lean toward explicit columns or sometimes keep it simple with SELECT *?

Collapse
 
dotallio profile image
Dotallio

I used to use SELECT * until a schema change broke an integration for me - since then, I always go explicit in anything production. Ever hit weird issues when a table structure changes?

Collapse
 
quentin_g_7de94987985cd3c profile image
Quentin G

An explicit SQL request should be more resilient than a select * in case of changes in the database structure, which can happen when a third party editor deploys an upgrade for example.

Collapse
 
shricodev profile image
Shrijal Acharya

Always use explicit column names. Wildcard like * can always lead to disasters in case of few changes in the DB schema.

Collapse
 
proxyorb profile image
ProxyOrb

I'm going all in, I use SELECT * more often.

Postgres on Neon - Get the Free Plan

No credit card required. The database you love, on a serverless platform designed to help you build faster.

Get Postgres on Neon