pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
psql format result as markdown tables
6+ messages / 5 participants
[nested] [flat]

* psql format result as markdown tables
@ 2018-01-13 09:50 Nicolas Paris <niparisco@gmail.com>
  2018-01-13 22:10 ` Re: psql format result as markdown tables Melvin Davidson <melvin6925@gmail.com>
  2018-01-13 22:19 ` Re: psql format result as markdown tables Stephen Frost <sfrost@snowman.net>
  2018-01-14 19:44 ` Re: psql format result as markdown tables Vick Khera <vivek@khera.org>
  0 siblings, 3 replies; 6+ messages in thread

From: Nicolas Paris @ 2018-01-13 09:50 UTC (permalink / raw)
  To: pgsql-general

Hello

I wonder if someone knows how to configure psql to output results as
markdown tables. 
Then instead of :

SELECT * FROM (values(1,2),(3,4)) as t;
 column1 | column2 
---------+---------
       1 |       2
       3 |       4

Get the result as :
SELECT * FROM (values(1,2),(3,4)) as t;
| column1 | column2| 
|---------|--------|-
|       1 |       2|
|       3 |       4|

Thanks by advance




^ permalink  raw  reply  [nested|flat] 6+ messages in thread

* Re: psql format result as markdown tables
  2018-01-13 09:50 psql format result as markdown tables Nicolas Paris <niparisco@gmail.com>
@ 2018-01-13 22:10 ` Melvin Davidson <melvin6925@gmail.com>
  2018-01-13 22:25   ` Re: psql format result as markdown tables Stephen Frost <sfrost@snowman.net>
  2 siblings, 1 reply; 6+ messages in thread

From: Melvin Davidson @ 2018-01-13 22:10 UTC (permalink / raw)
  To: Nicolas Paris <niparisco@gmail.com>; +Cc: pgsql-general

On Sat, Jan 13, 2018 at 4:50 AM, Nicolas Paris <niparisco@gmail.com> wrote:

> Hello
>
> I wonder if someone knows how to configure psql to output results as
> markdown tables.
> Then instead of :
>
> SELECT * FROM (values(1,2),(3,4)) as t;
>  column1 | column2
> ---------+---------
>        1 |       2
>        3 |       4
>
> Get the result as :
> SELECT * FROM (values(1,2),(3,4)) as t;
> | column1 | column2|
> |---------|--------|-
> |       1 |       2|
> |       3 |       4|
>
> Thanks by advance
>
>
*A. You have not graced us with PostgreSQL version and O/S*
*B. Your two examples appear exactly the same.*
*C. Have you looked at https://donatstudios.com/CsvToMarkdownTable
<https://donatstudios.com/CsvToMarkdownTable; ?*


*Found with a google search of .... sql markdown table*

-- 
*Melvin Davidson*
I reserve the right to fantasize.  Whether or not you
wish to share my fantasy is entirely up to you.

^ permalink  raw  reply  [nested|flat] 6+ messages in thread

* Re: psql format result as markdown tables
  2018-01-13 09:50 psql format result as markdown tables Nicolas Paris <niparisco@gmail.com>
  2018-01-13 22:10 ` Re: psql format result as markdown tables Melvin Davidson <melvin6925@gmail.com>
@ 2018-01-13 22:25   ` Stephen Frost <sfrost@snowman.net>
  0 siblings, 0 replies; 6+ messages in thread

From: Stephen Frost @ 2018-01-13 22:25 UTC (permalink / raw)
  To: Melvin Davidson <melvin6925@gmail.com>; +Cc: Nicolas Paris <niparisco@gmail.com>; pgsql-general

Greetings Melvin,

* Melvin Davidson (melvin6925@gmail.com) wrote:
> On Sat, Jan 13, 2018 at 4:50 AM, Nicolas Paris <niparisco@gmail.com> wrote:
> > I wonder if someone knows how to configure psql to output results as
> > markdown tables.
> > Then instead of :
> >
> > SELECT * FROM (values(1,2),(3,4)) as t;
> >  column1 | column2
> > ---------+---------
> >        1 |       2
> >        3 |       4
> >
> > Get the result as :
> > SELECT * FROM (values(1,2),(3,4)) as t;
> > | column1 | column2|
> > |---------|--------|-
> > |       1 |       2|
> > |       3 |       4|
> >
> > Thanks by advance
>
> *A. You have not graced us with PostgreSQL version and O/S*

While it can make a difference, it doesn't in this case, as far as I can
tell.  You can see the list of formats supported by each version of
PostgreSQL by going to:

https://www.postgresql.org/docs/current/static/app-psql.html

and then you can walk backwards through the various releases.

> *B. Your two examples appear exactly the same.*

Not true, actually, if you look carefully you'll see that there's a set
of pipes down the left-hand side, and pipes all down the middle (instead
of a '+' on the linebreak between the header and the data).  Those kinds
of differences are what would make having an actual markdown output
format for psql particularly useful as, otherwise, you have to
hand-massage it or use another tool.

> *C. Have you looked at https://donatstudios.com/CsvToMarkdownTable
> <https://donatstudios.com/CsvToMarkdownTable; ?*

That might be helpful in this case, though it would require sending data
to an 3rd party, which might not be ideal.  There's a number of
csv2markdown tools out there though which could be installed locally.
Not quite as nice as having the support in psql for it though.

Thanks!

Stephen

Attachments:

  signature.asc (application/pgp-signature, 818B) download

^ permalink  raw  reply  [nested|flat] 6+ messages in thread

* Re: psql format result as markdown tables
  2018-01-13 09:50 psql format result as markdown tables Nicolas Paris <niparisco@gmail.com>
@ 2018-01-13 22:19 ` Stephen Frost <sfrost@snowman.net>
  2018-01-13 23:12   ` Re: psql format result as markdown tables Tom Lane <tgl@sss.pgh.pa.us>
  2 siblings, 1 reply; 6+ messages in thread

From: Stephen Frost @ 2018-01-13 22:19 UTC (permalink / raw)
  To: Nicolas Paris <niparisco@gmail.com>; +Cc: pgsql-general

Hi Nicolas!

* Nicolas Paris (niparisco@gmail.com) wrote:
> I wonder if someone knows how to configure psql to output results as
> markdown tables. 

Unfortunately, I don't believe we support markdown as an output format
as yet.  To change the output format, you can use '\pset format html'.

You can see the list of formats supported by psql here:

https://www.postgresql.org/docs/current/static/app-psql.html

Look for 'format' or 'asciidoc' in that page to find the list quickly.

I suspect that if someone wanted to write the code to have markdown be
available that it would certainly be accepted, as that's definitely a
popular format.

Thanks!

Stephen

Attachments:

  signature.asc (application/pgp-signature, 818B) download

^ permalink  raw  reply  [nested|flat] 6+ messages in thread

* Re: psql format result as markdown tables
  2018-01-13 09:50 psql format result as markdown tables Nicolas Paris <niparisco@gmail.com>
  2018-01-13 22:19 ` Re: psql format result as markdown tables Stephen Frost <sfrost@snowman.net>
@ 2018-01-13 23:12   ` Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 0 replies; 6+ messages in thread

From: Tom Lane @ 2018-01-13 23:12 UTC (permalink / raw)
  To: Stephen Frost <sfrost@snowman.net>; +Cc: Nicolas Paris <niparisco@gmail.com>; pgsql-general

Stephen Frost <sfrost@snowman.net> writes:
> I suspect that if someone wanted to write the code to have markdown be
> available that it would certainly be accepted, as that's definitely a
> popular format.

Somebody was working on that awhile ago,

https://www.postgresql.org/message-id/flat/CAAYBy8YU4pXYKDHeQhsA_%3DFC93yOBZp5j1h%3DBSSAo9-oLcwNww%4...

Seems to have lost interest though ...

			regards, tom lane




^ permalink  raw  reply  [nested|flat] 6+ messages in thread

* Re: psql format result as markdown tables
  2018-01-13 09:50 psql format result as markdown tables Nicolas Paris <niparisco@gmail.com>
@ 2018-01-14 19:44 ` Vick Khera <vivek@khera.org>
  2 siblings, 0 replies; 6+ messages in thread

From: Vick Khera @ 2018-01-14 19:44 UTC (permalink / raw)
  To: Nicolas Paris <niparisco@gmail.com>; +Cc: pgsql-general

How does this work for you? I use this to get tables to insert into my
wiki, which are basically the format you want. I just delete the extra
lines I don't want at the end.

vk=> SELECT * FROM (values(1,2),(3,4)) as t;
 column1 | column2
---------+---------
       1 |       2
       3 |       4
(2 rows)

Time: 37.888 ms
vk=> \pset border 2
Border style is 2.
vk=> SELECT * FROM (values(1,2),(3,4)) as t;
+---------+---------+
| column1 | column2 |
+---------+---------+
|       1 |       2 |
|       3 |       4 |
+---------+---------+
(2 rows)

For you it looks like you need to change the "+" to "|" and it will work
and delete the first and last lines. I don't know if you can change that
with some other \pset setting.

On Sat, Jan 13, 2018 at 4:50 AM, Nicolas Paris <niparisco@gmail.com> wrote:

> Hello
>
> I wonder if someone knows how to configure psql to output results as
> markdown tables.
> Then instead of :
>
> SELECT * FROM (values(1,2),(3,4)) as t;
>  column1 | column2
> ---------+---------
>        1 |       2
>        3 |       4
>
> Get the result as :
> SELECT * FROM (values(1,2),(3,4)) as t;
> | column1 | column2|
> |---------|--------|-
> |       1 |       2|
> |       3 |       4|
>
> Thanks by advance
>
>

^ permalink  raw  reply  [nested|flat] 6+ messages in thread


end of thread, other threads:[~2018-01-14 19:44 UTC | newest]

Thread overview: 6+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2018-01-13 09:50 psql format result as markdown tables Nicolas Paris <niparisco@gmail.com>
2018-01-13 22:10 ` Melvin Davidson <melvin6925@gmail.com>
2018-01-13 22:25   ` Stephen Frost <sfrost@snowman.net>
2018-01-13 22:19 ` Stephen Frost <sfrost@snowman.net>
2018-01-13 23:12   ` Tom Lane <tgl@sss.pgh.pa.us>
2018-01-14 19:44 ` Vick Khera <vivek@khera.org>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox