3 ms·
Some time ago, I settled on a fairly similar idiosyncratic indentation style for SQL: select members.firstname as "First Name", members.lastname as "
by Semiapies 10y ago
Some time ago, I settled on a fairly similar idiosyncratic indentation style for SQL:
select
members.firstname as "First Name",
members.lastname as "Last Name"
from
borrowings
join
books on borrowings.bookid = books.bookid
join
members on members.memberid = borrowings.memberid
where
books.author = 'Dan Brown';
Normally, I'm a fairly slavish follower of style standards, but almost every bit of SQL I come across in my job is an unreadable mess, even when whoever wrote it did have the vague idea that consistent formatting was good.
- sbuttgereit 10y agoSometimes with complex queries, it can be tough to adhere to a simple set of style rules while also making clear where things like logical units start/stop. Don't get me wrong I'm not disagreeing with you in principle; but acknowledging that the declarative nature of the language cause you to break style for the sake of readability in some cases. I'm not going to post an example of such a case (I'd have to go digging and I'm too tired). On a different note, I don't like a lot of the styles I do see. I like yours, with the exception of the joins. My convention is a bit different: SELECT members.firstname as "First Name" ,members.lastname as "Last Name" FROM borrowings JOIN books ON borrowings.bookid = books.bookid JOIN members ON members.memberid = borrowings.memberid WHERE books.author = 'Dan Brown'; Some of that is old habit (like the comma first thing which I know is out of favor with many) which I found useful when working with long column lists. I'd also typically and systematically alias the tables, but that wasn't done in the examples. Outside of tastes, the only real downside I run into is that it's easy to get too far to the right with the indentation style I use. But it's not that often that I get there.
- Semiapies 10y agoI haven't had trouble with complicated queries with this style. I've been doing it for ages, though. There nothing wrong with comma-first, it's sensible; I just never got into the habit. My joins are so I can instantly glance over the tables involved in a query. (And, oh yes, I, too, normally alias the crap out of tables if there's more than one in a query.)