Live data from Hacker News

Show HN: Readsql – convert SQL to most human readable format

github.com

21–30 of 32 posts

Re: Show HN: Readsql – convert SQL to most human readable format

#21

Was expecting something like DESCRIBE but for less technical audience. As a heavy SQL user, I don't see much benefit in this as of yet. It is very misleading in saying it is the "most human readable" format, when the example shows the "format" to be identical to the original. Just by upper-casing keywords doesn't make it any more readable to be honest. Anyways a good attempt, hope you're not offended by critical feed…

Thank you for the feedback. The example in Github has code highlighting. I wonder if I should remove that and if that would make more difference. I would be interested to know how this tool could help you with your SQL usage

Re: Show HN: Readsql – convert SQL to most human readable format

#22
post #12

Earlier quoted context omitted.

I understand the wonder, this is not some kind of magic that will help us solve all SQL issues. That's way too hard. This is a development tool that helps write and read SQL code. So simply saves development time by automating the easy stuff, leaving the hard and important stuff for us to deal with. It is different from other formatters that it lints code inside Python strings. For some context, I am a data engineer…

Ok that puts it in context a little bit, if it’s making your life easier then it must be useful to people in the same position and role. I’ve o it ever written SQL in stored procs and one off queries so relied on Redgates SQL Prompt tool (you might want to take a look at what that does for some inspiration)

Thank you, I can definitely look up for some inspiration from Redgates. I see that it also costs some money

Re: Show HN: Readsql – convert SQL to most human readable format

#23

Does it do anything but uppercase keywords? Is it going to add line breaks or indentation at some point?

Adding line breaks before FROM, JOIN, WHERE, GROUP BY, ORDER BY, LIMIT/OFFSET (and usually before some of the ANDs) is the first thing I do when analyzing some SQL. Capitalization is rarely needed after that and useful for longer term readability. I also normalize by removing optional/redundant keyword noise, I'm looking at you INNER/OUTER.

Thanks, that's definitely coming in the near future

Re: Show HN: Readsql – convert SQL to most human readable format

#24
post #21

Was expecting something like DESCRIBE but for less technical audience. As a heavy SQL user, I don't see much benefit in this as of yet. It is very misleading in saying it is the "most human readable" format, when the example shows the "format" to be identical to the original. Just by upper-casing keywords doesn't make it any more readable to be honest. Anyways a good attempt, hope you're not offended by critical feed…

Thank you for the feedback. The example in Github has code highlighting. I wonder if I should remove that and if that would make more difference. I would be interested to know how this tool could help you with your SQL usage

Every IDE I use and have used for the last 15 years has included an option to format the code the way someone else believes it to be best viewed. I have never found these to be the way I prefer SQL to be formatted for the best readability.

A difficult but incredibly useful idea would be to learn the developer’s style and then format code (theirs or others’) to fit that model.

Re: Show HN: Readsql – convert SQL to most human readable format

#25
post #16

Leaving aside the modest achievements of the code so far, the missing prerequisite to "automatically" formatting SQL is... just formatting SQL. Because SQL (broadly) was designed to be "human" readable in the first place, it's grammatically very inconsistent and with a lot of keywords. Much more than other languages in use today such as C. I've yet to find a pattern of indentation, brackets etc. that satisfies my OCD…

I make an effort to indent on most keywords, using a Python-like structure to indent related lines to the same level, one more than the keyword operating on them all, with the heuristic that if I can comment one or more lines to debug, I have a readable query.

I tend to classify SQL statements into two kinds, those that when wrapped in a calling function fit in one screen, and those other longer ones that I'm inclined to write in an imperative language.

Edit: For the author of the repository, the list of reserved words gets longer and more complex when you support different implementations of SQL, and regex may be insufficient once you consider such parsing questions as whether the keyword is within quotation marks or part of a user-defined name.

https://www.drupal.org/docs/develop/coding-standards/list-of...

https://github.com/AzisK/readsql/blob/master/readsql/regexes...

Re: Show HN: Readsql – convert SQL to most human readable format

#26
post #25
post #16

Leaving aside the modest achievements of the code so far, the missing prerequisite to "automatically" formatting SQL is... just formatting SQL. Because SQL (broadly) was designed to be "human" readable in the first place, it's grammatically very inconsistent and with a lot of keywords. Much more than other languages in use today such as C. I've yet to find a pattern of indentation, brackets etc. that satisfies my OCD…

I make an effort to indent on most keywords, using a Python-like structure to indent related lines to the same level, one more than the keyword operating on them all, with the heuristic that if I can comment one or more lines to debug, I have a readable query. I tend to classify SQL statements into two kinds, those that when wrapped in a calling function fit in one screen, and those other longer ones that I'm incline…

Thank you for the feedback and for the link. This is something I also do for SQL code. Initially I was making this to be used as a pre-commit hook for SQL code inside Python for our team. Probably inspired by the black Python formatter. I just made the MVP and will propose to our team to use it after the holidays. If regexes would seem to be not enough, we still have the power of Python to lend a hand for more complex puzzles

Re: Show HN: Readsql – convert SQL to most human readable format

#27
post #3

Earlier quoted context omitted.

For now it only upper-cases but I would like it to "prettify" the code as well. So it is an upcoming feature. Hopefully it will even suggest SQL code improvements in the future. Contributions are welcome

I don't really get it. Is upper case more human readable than lower case?

Me neither, when copying uppercase sql i always lowercase everything. But I can understand that some people are more used to that format even though I find it obsolete.

In any case, it is objectively not more human writeable.

Post reply on HN