I vote against implementing this as a feature, because way too many people are struggling with the current formatting options already.
Of course, such a formatting feature could be made available based on reputation or something, but people don't seem to like that idea.
But I too get annoyed at database questions, sometimes because I wish I has a graphical view of their DB, and the OP only provided an SQL dump, and sometimes because the OP actually made the effort of creating some ASCII art, but I wish I had an actual SQL to play around with.
On Code Golf SE it is common practice to use stack snippets to display leaderboards, i.e. tables.
So why not use them to process CSV?
Admittedly, this is more of a workaround than an actual solution, but I think it would still be better than having a ton of 1-rep users presented with yet another formatting feature just waiting to be abused over and over.
Users who do a little research and read through the help center can be trusted with formatting options though, IMO.
So, my suggestion is:
Come up with some JavaScript to take CSV, and format it, or build SQL from it (or whatever your heart desires), and put that somewhere into the help center.
Example snippet & data:
(Warning: JS was made in <3 min and does not reliably parse CSV, it's only for PoC!)
var d=document,b=d.body,h='',s=d.createElement('style');b.firstChild.textContent.trim().split('\n').forEach(function(l){h+='<tr>';l.split(',').forEach(function(c){h+='<td>'+c+'</td>'});h+='</tr>'});b.innerHTML='<table>'+h+'</table>';s.innerHTML='td{border:solid 1px #CCC;padding:5px;}';d.head.appendChild(s);
Id,Name,Age
1,James,20
2,Jane,20
The JS can be golfed to a one-liner, the data could be put in the HTML or CSS field (I chose HTML here), so by default, you could look at the raw CSV data, and upon pressing "Run code snippet", you'd have it displayed as a nice table.
Of course the code could (and likely should) then be expanded to switch between table and SQL view, display the table header in <th>
s instead of <td>
s, etc.
An entry could then be added to the Editing Help page (I know it's not technically part of the help center, but still...), like:
Database schemas, CSV and SQL
In order to present your database schema in the most useful and clear way, the community has come up with some code.
To use it, press Ctrl+M or click on "JavaScript/HTML/CSS snippet" in the editor, then insert your SQL/CSV into the "HTML" field and paste this line into the "JavaScript" field:
var d=document,b=d.body,h='',s=d.createElement('style');b.firstChild.textContent.trim().split('\n').forEach(function(l){h+='<tr>';l.split(',').forEach(function(c){h+='<td>'+c+'</td>'});h+='</tr>'});b.innerHTML='<table>'+h+'</table>';s.innerHTML='td{border:solid 1px #CCC;padding:5px;}';d.head.appendChild(s);
Edit:
Someone posted a comment (which was soon after deleted) with a link to an answer on Meta DBA with the same idea.
Given that the status of the question is status-declined (even for DBA!), I think this is by far our best option.
[SOCsvToTable] csv data [\SOCsvToTable]
would work.|
), like you'd use 4 spaces for a normal code block, what's to stop users from using the wrong formatting option? Users have enough trouble formatting code as it is, already. Those[]
blocks you suggested seem more reliable, indeed.