SQLTeam.com | Weblogs | Forums

How to Format SQL code and results in the Discourse forum


OK, so I know this has probably been answered somewhere but I couldn't seem to make this happen in my post yesterday. How do you format the SQL code you post in the new forums? I generated my create table script and example data using ConvertCSV site, formatted my results using Senseful site, and then pasted my attempt at the query plus all of the above into PoorSQL to format it. However when I pasted it back into these forums, it was all over the place in my post and the highlighting had gone. The response from the forum members was very fast as I had provided all the necessary info, but how do I format my future posts nicely for you guys to read more easily?

Thank you


using the [</>] button (which works, but is a bit crude in its approach) or by prefix / suffix your code block with:


    ... your code here ...


you can also use


    ... some plain text here ...


if you want to post, say, some results output, or something that you do NOT want syntax-highlighted


P.S. If you want to, you can go back and re-edit earlier post(s) by using the PENCIL icon, and pop those code-formatting directives into the original content.


Thanks Kristen,

I remembered how to do it on the old forums but could not see it on the new ones. I'll have a play on my post from yesterday to try it out (bitsmed has already answered my question).


FWIW, I hand enter [ code] and [ /code] (remove the space after the open square bracket) around any SQL I supply and it preserves the formatting. The only mini-gripe is that the TABs in the code are too big by default so I find and replace with some spaces.


Thank you, that is also useful to know.


I started off using those tags, as it was familiar to me from old forum and other forums, but any lines that are blank are omitted, so I gave up on it in favour of the ```SQL notation

Personally I would much prefer a TAG system, where the user has to deliberately indicate formatting, because this system infers it from content and all sorts of things muck it up

If I type "You can use COUNT(*) in the first statement and also COUNT(*) in the second" it will display like this (I've carefully edited the asterisks in this paragraph, but you have to know that the formatter will gobble and react to those characters :frowning:

"You can use COUNT() in the first statement and also COUNT() in the second"