-10

In many cases, we find queries look like this ugly and unread query :

update P20_Extract_Invoice n1,P20_Extract_Invoice n2 set n1.Closure_Status = 'FAILURE',n1.Failure_Reason = 'DUPLICATE_ENTRY' where n1.WorkItemID = n2.WorkItemID and n1.ID != n2.ID and n1.Closure_Status = 'PICKED_FOR_PROCESSING' and n2.Closure_Status = 'PICKED_FOR_PROCESSING';

Usually I use one of the sites which provide SQL formatting service :

The result is beautiful :

update
   P20_Extract_Invoice n1, P20_Extract_Invoice n2 
set
   n1.Closure_Status = 'FAILURE', n1.Failure_Reason = 'DUPLICATE_ENTRY' 
where
   n1.WorkItemID = n2.WorkItemID 
   and n1.ID != n2.ID 
   and n1.Closure_Status = 'PICKED_FOR_PROCESSING' 
   and n2.Closure_Status = 'PICKED_FOR_PROCESSING';

I think its time to add this functionality to the header :

SQL Formatter

3
  • 5
    Wouldn't we then need a formatting button for almost all languages? Don't know how ofter I fixed C++ code formatting.
    – BDL
    Apr 2, 2018 at 15:19
  • 1
    I hate that formatting. I like mine.
    – fbueckert
    Apr 2, 2018 at 22:17
  • It's the OP's fault to write ugly code. Just downvote the question, comment "please format your code with code formatting and indent your code properly", and move on.
    – user202729
    Apr 3, 2018 at 5:19

2 Answers 2

-6

I am starting to think most people here use downvote button for "I don't agree with OP", even if his question was clear, well argumented and calls for a healthy discussion.

Personally, I do agree with OP, as SQL is very cross-platform and enjoyed by many people who actually do their "main coding" with all kind of languages. What comes to "we should then offer formatting for language X, Y and Z" -argument. Maybe we should? It should be obvious that certain languages are more popular than the others, so we are going to see much more JS/CSS/Java/Popular_Framework -questions than Red or R questions etc. As the usage of ANY formatting option is up to the OP, it shouldn't be a problem to offer some more choices, as you can always decline if you feel your own formatting does well enough.

I think this question is very similar to code block word wrapping. Many (if not most) of us would like the long lines to be wrapped, but as some/few/many/others think it should not be done, then they do not want to allow that possibility for others either.

The real question then seems to be, should we add disagree/agree -votes to separate good questions from bad and "a matter of taste" -questions.. Not good for the meta when good questions get no views, because people assume it was a shitty question - just because n+10 first people bothering to vote thought to downvote because they disagreed with the OP.

8
  • 3
    Your first sentence is a correct assumption. You can see how it works here.
    – jhpratt
    Apr 3, 2018 at 2:36
  • I downvoted, not exactly because I disagree with the OP, but because the OP hasn't provided any research or evidence why this would be a useful feature. As the OP has already stated, there exist online tools that will do this exact same thing for you. If we want Stack Overflow to do this automatically, why don't we start introducing the Stack Overflow code style indenter? Or the Stack Overflow character counter? Or the Stack Overflow Spell Checker? My point is saying: "I want SO to have this" isn't a researched reason for a feature request, especially when other sites can do it for us easily.
    – Davy M
    Apr 3, 2018 at 2:58
  • 1
    @DavyM With that logic every single feature that stack has, could be done "in another site", so there would be no point to offer it for users? I'd say with my "research" that it would be nice for ALL, if people who are too ignorant or lazy to use "other sites", could at least format their code using a built-in-tool. Mostly I have hard time seeing any real negative sides for offering this type of tools, not counting the fact that it does mean more work for the site upkeepers. It's hard to get "research input" if people downvote your question so that nobody answers or comments them.. Apr 3, 2018 at 3:08
  • @StackingForHeap I didn't say any feature that can be done elsewhere shouldn't be done here, I said the OP has provided no justification as to why this feature should be done here. When someone forms a feature request, it should be accompanied by reasons and justifications why it is worthwhile to go through the work to implement the change. The OP's whole argument is "I do <explanation of the sites he uses>. I think its time to add this functionality to the header". All he's said is that he wants something to be here, but he hasn't given any justification as to why it's a useful addition.
    – Davy M
    Apr 3, 2018 at 3:14
  • 1
    @DavyM Maybe you are expecting a bit more "hard data" here, I think he showed an often seen SQL query and presented an alternative way that (using common standards) IS much more readable and "beautiful". I would call that a justification and meaningful argument. Maybe one could argue it is a matter of taste. Just to entertain the idea, how would you personally organize a vote to get this hard data of how many users would like to see this formatting or like to use it as "built in" -feature? Apr 3, 2018 at 3:17
  • @StackingForHeap My version of this feature request would sound more like "I see this recurring issue of bad sql queries, like on these questions <2 or 3 citations>. These are difficult to read, however there are algorithms to easily reformat them, like <website>. However, plugging it into <website> is inconvenient because <x, y, z reasons>. If SO were to provide this functionality and add a button that would format a block of text, <list of benefits>. ". See the difference? The current request is just a "I like this, let's do it," whereas this would have research and justification.
    – Davy M
    Apr 3, 2018 at 3:23
  • 1
    @DavyM I see the difference, but I also think it's somewhat semantics, as you are practically saying the same thing with a bit more words used. "This are difficult to read", "easily reformat" and "inconvenient" are all matters of personal taste, unless we could show that X number of people agree or disagree with your statement. This cannot be really done here, unless we have a voting system or allow people to disagree without downvoting the post/question itself. But I do see your point too, maybe it could have been reasoned with a bit more detail added. Apr 3, 2018 at 3:28
  • It's not about making a vote or gathering hard data about how many people think it's useful, it's showing why the feature would be useful instead of simply telling us that it is. Don't just tell me that you like the feature, make me like it.
    – Davy M
    Apr 3, 2018 at 3:28
7

If we did this, we'd also want to incorporate functionality for ensuring full-on conventional indentation for Java (including putting the { in the "right" place), and ensuring that Python uses spaces for indentation consistently.

Kind of a slippery slope there, and the language lexers don't really care how it's formatted so long as it's syntactically correct.

This is the kind of thing I'd expect 2K+ editors to handle; this kind of edit shouldn't be in the review queues, but it definitely improves the question. The OP should format their code, but if they don't, it shouldn't be regarded as a grave offense when someone (like you or myself) can just come in and format it for them instead.

0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .