diff -ru a/src/bin/psql/command.c b/src/bin/psql/command.c --- a/src/bin/psql/command.c 2017-02-06 22:45:25.000000000 +0100 +++ b/src/bin/psql/command.c 2017-02-28 01:07:26.000000000 +0100 @@ -2584,9 +2584,17 @@ popt->topt.line_style = &pg_asciiformat_old; else if (pg_strncasecmp("unicode", value, vallen) == 0) popt->topt.line_style = &pg_utf8format; + /* format markdown + */ + else if (pg_strncasecmp("markdown", value, vallen) == 0) + popt->topt.line_style = &pg_markdown; + /* format rst + */ + else if (pg_strncasecmp("rst", value, vallen) == 0) + popt->topt.line_style = &pg_rst; else { - psql_error("\\pset: allowed line styles are ascii, old-ascii, unicode\n"); + psql_error("\\pset: allowed line styles are ascii, old-ascii, unicode, markdown\n"); return false; } diff -ru a/src/fe_utils/print.c b/src/fe_utils/print.c --- a/src/fe_utils/print.c 2017-02-06 22:45:25.000000000 +0100 +++ b/src/fe_utils/print.c 2017-02-28 13:34:11.000000000 +0100 @@ -57,6 +57,48 @@ static printTableFooter default_footer_cell = {default_footer, NULL}; /* Line style control structures */ +const printTextFormat pg_markdown = +{ + "markdown", + { + {"", "", "", ""}, + {"-", "|", "|", "|"}, + {"", "", "", ""}, + {"", "|", "|", "|"} + }, + "|", + "|", + "|", + " ", + "+", + " ", + " ", + ".", + ".", + true +}; + +const printTextFormat pg_rst = +{ + "rst", + { + {"-", "+", "+", "+"}, + {"=", "+", "+", "+"}, + {"-", "+", "+", "+"}, + {"", "|", "|", "|"} + }, + "|", + "|", + "|", + " ", + "+", + " ", + "+", + ".", + ".", + true +}; + const printTextFormat pg_asciiformat = { "ascii", @@ -623,6 +665,12 @@ if (opt_border > 2) opt_border = 2; + if (format == &pg_markdown) + opt_border = 2; + + if (format == &pg_rst) + opt_border = 2; + if (cont->ncolumns > 0) { col_count = cont->ncolumns; @@ -1124,13 +1172,20 @@ fputc('\n', fout); } while (more_lines); + + /* add line after every record */ + if (opt_border == 2 && format == &pg_rst) + _print_horizontal_line(col_count, width_wrap, opt_border, + PRINT_RULE_BOTTOM, format, fout); } if (cont->opt->stop_table) { printTableFooter *footers = footers_with_default(cont); - if (opt_border == 2 && !cancel_pressed) + /* dont add line after last row, because line is added after every row + **/ + if ((opt_border == 2 && format != &pg_rst) && !cancel_pressed) _print_horizontal_line(col_count, width_wrap, opt_border, PRINT_RULE_BOTTOM, format, fout); @@ -1138,6 +1193,9 @@ if (footers && !opt_tuples_only && !cancel_pressed) { printTableFooter *f; + /*add newline after table because rst needs empty line after table + */ + fprintf(fout, "\n"); for (f = footers; f; f = f->next) fprintf(fout, "%s\n", f->data); diff -ru a/src/include/fe_utils/print.h b/src/include/fe_utils/print.h --- a/src/include/fe_utils/print.h 2017-02-06 22:45:25.000000000 +0100 +++ b/src/include/fe_utils/print.h 2017-02-28 01:04:05.000000000 +0100 @@ -176,6 +176,8 @@ extern volatile bool cancel_pressed; extern const printTextFormat pg_asciiformat; +extern const printTextFormat pg_markdown; /*format pro markdown*/ +extern const printTextFormat pg_rst; /*format pro rst*/ extern const printTextFormat pg_asciiformat_old; extern printTextFormat pg_utf8format; /* ideally would be const, but... */