The other nice benefit is that, when you list the fields you're retrieving, it functions like a mini-reference as you write/modify your query, so you don't have to keep switching to the schema to see if it's called "id" or "row_id", if it's "package_name" or "pkgname"...
To me, "SELECT *" almost feels like using your variables without declaring them first -- not technically wrong in many languages, but still uncomfortable-feeling.
StringBuilder stringBuilder = new StringBuilder();
That is horrendously redundant. Var is handy shorthand and should be used!!
But what if you're doing something like
var x = myOtherObjectName.y;
readability is destroyed in this case. (stringBuilder :: StringBuilder) <- construct
(Assuming that there was a type class that had construct as a method and StringBuilder was an instance of that class.)I recall a problem with some Oracle views that were based on 'select <star>' queries. What we didn't realize is that the '*' is evaluated when the view is compiled, and if you later add columns to the underlying tables the view did not automatically include them.
Edit: OK I don't know how to include a literal star in text here.
EDIT: Nope, that wasn't it.
shakes fist at crazy home-grown not-quite-Markdown
Or you can make a *literal* line by putting two spaces before it.There's a huge difference between an application executing a sql statement:
SELECT * FROM accounts;
and a UDF like: CREATE OR REPLACE FUNCTION accounts__list_all()
RETURNS SETOF accounts
LANGUAGE SQL AS
$$
SELECT * FROM accounts ORDER BY account_no;
$$;
In the latter case the select * reduces maintenance points in your db because you have already tied the return type to the table type, so either you get to use the * or list all columns manually and the latter, given the requirement to list all every time, makes any schema changes incompatible with your API.