1

I have a similar question to this one (for Pandas), in that I'd like to have the results of an SQL query appear nicely in a Slack message, as a table.

If for example I output the query results as Markdown and then paste this in Jira, a table appears exactly as I'd like it, regardless of whether column names are in snake_case. However, if I choose the Markdown (raw) code snippet in Slack, underscores are interpreted as beginning italics, which is completely wrong.

Does anyone have a better suggestion for displaying tabular results? Or forcing Markdown (raw) to ignore underscores? I tried code blocks as well but to no avail.

For info, the database IDE I'm using is DataGrip.

Ricky McMaster
  • 4,289
  • 2
  • 24
  • 23

3 Answers3

3

Slack does not have support for tables, like Jira. So your only option to to choose from workarounds. I see 3 available approaches:

1) Display in external browser

Store your data in an external web app and just post a link to Slack. That works very e.g. with Google Sheets if you use the Google Apps integrator in your Slack workspace.

2) Display as image

Another option is to generate an image (e.g. GIF) from your table and then post the image to Slack. That way the data can be displayed within Slack. To safe Slack storage space I would suggest storing the image file in an external image service (e.g. imgur) and then only post the link. Imgur has an API which would allow this process to be fully automated.

3) Display as plain text

Building upon one of the answers from the question you linked you can also convert your table into a plain text using a tool like Tabulate and then upload it as plain text snippet to Slack. That way the table could also be viewed within Slack. Note that the max size for snippet uploads is 1MB. Also, Slack will only show the first fews lines by default.

Erik Kalkoken
  • 30,467
  • 8
  • 79
  • 114
3

Doug here, creator of SQLBot.co. Tables are not supported in Slack, but you can get pretty close using ascii tables and code formating (three tick marks to begin and end)

Here's an example: enter image description here

The only issue is that if your table gets too wide the text wraps.

Depending on how you're generating the output there may be good helpers. In the ruby world you can use the terminal-table gem or the text-table gem.

DougB
  • 674
  • 7
  • 14
0

Since this comes up on a google search, and the site mentioned previously requires signup, thought I'd share what I found: https://ozh.github.io/ascii-tables/

Just paste the output in Slack within a Code Block

  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Feb 26 '22 at 10:01