There it is, what i have.
I need i small help with psql.out, because \pset format wrapped. I don`t
know, how to have it in fixed width.
2017-02-28 14:23 GMT+01:00 Jan Michálek <[email protected]>:
> Current state is something like this (diff is attached).
> I currently haven`t regression test, tab completion etc., I will add this
> thing following structure of asciidoc commit.
>
> Output is tested using retext, rst is OK, md have problem with cells with
> newline (i must find out, how it is possible create table with this in
> markdown).
>
> [jelen@laptak patch_postgre_rst]$
> [jelen@laptak psql]$ ./psql
> psql (9.6.2, server 9.6.1)
> Type "help" for help.
>
> jelen=# \pset linestyle markdown
> Line style is markdown.
> jelen=# values(E'nasral Franta\nna trabanta','Žluťoučký kobyly'),
> ('''',E'a\tb') \g | xclip
> jelen=# values(E'nasral Franta\nna trabanta','Žluťoučký kobyly'),
> ('''',E'a\tb') \g
>
> | column1 | column2 |
> |---------------|------------------|
> | nasral Franta | Žluťoučký kobyly |
> | na trabanta | |
> | ' | a b |
>
>
> (2 rows)
>
> jelen=# \pset linestyle rst
> Line style is rst.
> jelen=# values(E'nasral Franta\nna trabanta','Žluťoučký kobyly'),
> ('''',E'a\tb') \g
> +---------------+------------------+
> | column1 | column2 |
> +===============+==================+
> | nasral Franta+| Žluťoučký kobyly |
> | na trabanta | |
> +---------------+------------------+
> | ' | a b |
> +---------------+------------------+
>
> (2 rows)
>
> jelen=#
>
> 2017-02-24 0:46 GMT+01:00 Michael Paquier <[email protected]>:
>
>> On Fri, Feb 24, 2017 at 3:09 AM, Jan Michálek <[email protected]>
>> wrote:
>> > I can try it, doesn`t look dificult, but I`m worry, that I`m not able to
>> > write clean, pretty code.
>>
>> If you want to have something available in Postgres 10, you had better
>> be quick. The last commit fest of the development cycle of Postgres 10
>> begins on the 1st of March, you need to to register your patch here:
>> https://commitfest.postgresql.org/13/
>> Here are also some rough guidelines about submitting a patch:
>> https://wiki.postgresql.org/wiki/Submitting_a_Patch
>> --
>> Michael
>>
>
>
>
> --
> Jelen
> Starší čeledín datovýho chlíva
>
--
Jelen
Starší čeledín datovýho chlíva
diff -ru a/doc/src/sgml/ref/psql-ref.sgml b/doc/src/sgml/ref/psql-ref.sgml
--- a/doc/src/sgml/ref/psql-ref.sgml 2017-02-06 22:45:25.000000000 +0100
+++ b/doc/src/sgml/ref/psql-ref.sgml 2017-03-01 00:37:19.000000000 +0100
@@ -2373,6 +2373,7 @@
<para>
Sets the border line drawing style to one
of <literal>ascii</literal>, <literal>old-ascii</literal>,
+ , <literal>rst</literal>, <literal>markdown</literal>
or <literal>unicode</literal>.
Unique abbreviations are allowed. (That would mean one
letter is enough.)
@@ -2408,6 +2409,12 @@
again in the left-hand margin of the following line.
</para>
+ <para><literal>rst</literal> and <literal>markdown</literal> format
+ tables for use restructured text on markdown documents. Both of them
+ works well only with format <literal>aligned</literal> and border
+ <literal>2</literal>.
+ </para>
+
<para>
When the <literal>border</> setting is greater than zero,
the <literal>linestyle</literal> option also determines the
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-03-01 01:12:17.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, rst\n");
return false;
}
diff -ru a/src/bin/psql/help.c b/src/bin/psql/help.c
--- a/src/bin/psql/help.c 2017-02-06 22:45:25.000000000 +0100
+++ b/src/bin/psql/help.c 2017-03-01 00:59:07.000000000 +0100
@@ -374,7 +374,7 @@
fprintf(output, _(" fieldsep_zero set field separator for
unaligned output to zero byte\n"));
fprintf(output, _(" footer enable or disable display of
the table footer [on, off]\n"));
fprintf(output, _(" format set output format [unaligned,
aligned, wrapped, html, asciidoc, ...]\n"));
- fprintf(output, _(" linestyle set the border line drawing
style [ascii, old-ascii, unicode]\n"));
+ fprintf(output, _(" linestyle set the border line drawing
style [ascii, old-ascii, unicode, rst, markdown]\n"));
fprintf(output, _(" null set the string to be printed in
place of a null value\n"));
fprintf(output, _(" numericlocale enable or disable display of a
locale-specific character to separate\n"
" groups of
digits [on, off]\n"));
diff -ru a/src/bin/psql/tab-complete.c b/src/bin/psql/tab-complete.c
--- a/src/bin/psql/tab-complete.c 2017-02-06 22:45:25.000000000 +0100
+++ b/src/bin/psql/tab-complete.c 2017-03-01 02:44:26.000000000 +0100
@@ -3075,7 +3075,7 @@
COMPLETE_WITH_LIST_CS(my_list);
}
else if (TailMatchesCS1("linestyle"))
- COMPLETE_WITH_LIST_CS3("ascii", "old-ascii", "unicode");
+ COMPLETE_WITH_LIST_CS5("ascii", "old-ascii", "unicode",
"rst", "markdown");
else if (TailMatchesCS1("unicode_border_linestyle|"
"unicode_column_linestyle|"
"unicode_header_linestyle"))
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-03-01 01:29:20.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... */
diff -ru a/src/test/regress/expected/psql.out
b/src/test/regress/expected/psql.out
--- a/src/test/regress/expected/psql.out 2017-02-06 22:45:25.000000000
+0100
+++ b/src/test/regress/expected/psql.out 2017-03-01 03:10:54.000000000
+0100
@@ -2714,3 +2714,87 @@
CONTEXT: PL/pgSQL function inline_code_block line 3 at RAISE
ERROR: bar
CONTEXT: PL/pgSQL function inline_code_block line 4 at RAISE
+prepare q AS VALUES(E'Elephant, kangaroo,\nsquirrel, gorilla', 121,
(279./278.)::text, 0.1111, repeat('Hello ', 50))
+ , (E'goat, rhinoceros,\nmonkey, ape', 11121, (1279./1278.)::text, 5.1111,
repeat('cigar from nicaragua ', 20))
+ , (E'donkey, cow, horse, tit,\neagle, whale,\naligator,
pelican,\ngrasshoper\npig\n\tbat', 14351, (12345./245.)::text, 345.11,
repeat('camfire ', 20));
+\pset format aligned
+\pset linestyle rst
+execute q;
++--------------------------+---------+---------------------+---------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
+| column1 | column2 | column3 | column4 |
column5
|
++==========================+=========+=====================+=========+======================================================================================================================================================================================================================================================================================================================================================================================================================================+
+| Elephant, kangaroo, | 121 | 1.0035971223021583 | 0.1111 | Hello
Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello
Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello
Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello
Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello
|
+| squirrel, gorilla | | | |
|
++--------------------------+---------+---------------------+---------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
+| goat, rhinoceros, | 11121 | 1.0007824726134585 | 5.1111 | cigar
from nicaragua cigar from nicaragua cigar from nicaragua cigar from nicaragua
cigar from nicaragua cigar from nicaragua cigar from nicaragua cigar from
nicaragua cigar from nicaragua cigar from nicaragua cigar from nicaragua cigar
from nicaragua cigar from nicaragua cigar from nicaragua cigar from nicaragua
cigar from nicaragua cigar from nicaragua cigar from nicaragua cigar from
nicaragua cigar from nicaragua |
+| monkey, ape | | | |
|
++--------------------------+---------+---------------------+---------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
+| donkey, cow, horse, tit, | 14351 | 50.3877551020408163 | 345.11 | camfire
camfire camfire camfire camfire camfire camfire camfire camfire camfire camfire
camfire camfire camfire camfire camfire camfire camfire camfire camfire
|
+| eagle, whale, | | | |
|
+| aligator, pelican, | | | |
|
+| grasshoper | | | |
|
+| pig | | | |
|
+| bat | | | |
|
++--------------------------+---------+---------------------+---------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
+
+(3 rows)
+
+\pset linestyle markdown
+execute q;
+| column1 | column2 | column3 | column4 |
column5
|
+|--------------------------|---------|---------------------|---------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
+| Elephant, kangaroo, | 121 | 1.0035971223021583 | 0.1111 | Hello
Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello
Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello
Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello
Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello
|
+| squirrel, gorilla | | | |
|
+| goat, rhinoceros, | 11121 | 1.0007824726134585 | 5.1111 | cigar
from nicaragua cigar from nicaragua cigar from nicaragua cigar from nicaragua
cigar from nicaragua cigar from nicaragua cigar from nicaragua cigar from
nicaragua cigar from nicaragua cigar from nicaragua cigar from nicaragua cigar
from nicaragua cigar from nicaragua cigar from nicaragua cigar from nicaragua
cigar from nicaragua cigar from nicaragua cigar from nicaragua cigar from
nicaragua cigar from nicaragua |
+| monkey, ape | | | |
|
+| donkey, cow, horse, tit, | 14351 | 50.3877551020408163 | 345.11 | camfire
camfire camfire camfire camfire camfire camfire camfire camfire camfire camfire
camfire camfire camfire camfire camfire camfire camfire camfire camfire
|
+| eagle, whale, | | | |
|
+| aligator, pelican, | | | |
|
+| grasshoper | | | |
|
+| pig | | | |
|
+| bat | | | |
|
+
+
+(3 rows)
+
+\pset format wrapped
+\pset linestyle rst
+execute q;
++--------------------------+---------+---------------------+---------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
+| column1 | column2 | column3 | column4 |
column5
|
++==========================+=========+=====================+=========+======================================================================================================================================================================================================================================================================================================================================================================================================================================+
+| Elephant, kangaroo, | 121 | 1.0035971223021583 | 0.1111 | Hello
Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello
Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello
Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello
Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello
|
+| squirrel, gorilla | | | |
|
++--------------------------+---------+---------------------+---------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
+| goat, rhinoceros, | 11121 | 1.0007824726134585 | 5.1111 | cigar
from nicaragua cigar from nicaragua cigar from nicaragua cigar from nicaragua
cigar from nicaragua cigar from nicaragua cigar from nicaragua cigar from
nicaragua cigar from nicaragua cigar from nicaragua cigar from nicaragua cigar
from nicaragua cigar from nicaragua cigar from nicaragua cigar from nicaragua
cigar from nicaragua cigar from nicaragua cigar from nicaragua cigar from
nicaragua cigar from nicaragua |
+| monkey, ape | | | |
|
++--------------------------+---------+---------------------+---------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
+| donkey, cow, horse, tit, | 14351 | 50.3877551020408163 | 345.11 | camfire
camfire camfire camfire camfire camfire camfire camfire camfire camfire camfire
camfire camfire camfire camfire camfire camfire camfire camfire camfire
|
+| eagle, whale, | | | |
|
+| aligator, pelican, | | | |
|
+| grasshoper | | | |
|
+| pig | | | |
|
+| bat | | | |
|
++--------------------------+---------+---------------------+---------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
+
+(3 rows)
+
+\pset linestyle markdown
+execute q;
+| column1 | column2 | column3 | column4 |
column5
|
+|--------------------------|---------|---------------------|---------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
+| Elephant, kangaroo, | 121 | 1.0035971223021583 | 0.1111 | Hello
Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello
Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello
Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello
Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello
|
+| squirrel, gorilla | | | |
|
+| goat, rhinoceros, | 11121 | 1.0007824726134585 | 5.1111 | cigar
from nicaragua cigar from nicaragua cigar from nicaragua cigar from nicaragua
cigar from nicaragua cigar from nicaragua cigar from nicaragua cigar from
nicaragua cigar from nicaragua cigar from nicaragua cigar from nicaragua cigar
from nicaragua cigar from nicaragua cigar from nicaragua cigar from nicaragua
cigar from nicaragua cigar from nicaragua cigar from nicaragua cigar from
nicaragua cigar from nicaragua |
+| monkey, ape | | | |
|
+| donkey, cow, horse, tit, | 14351 | 50.3877551020408163 | 345.11 | camfire
camfire camfire camfire camfire camfire camfire camfire camfire camfire camfire
camfire camfire camfire camfire camfire camfire camfire camfire camfire
|
+| eagle, whale, | | | |
|
+| aligator, pelican, | | | |
|
+| grasshoper | | | |
|
+| pig | | | |
|
+| bat | | | |
|
+
+
+(3 rows)
+
+deallocate q;
diff -ru a/src/test/regress/sql/psql.sql b/src/test/regress/sql/psql.sql
--- a/src/test/regress/sql/psql.sql 2017-02-06 22:45:25.000000000 +0100
+++ b/src/test/regress/sql/psql.sql 2017-03-01 02:50:50.000000000 +0100
@@ -379,3 +379,19 @@
raise notice 'foo';
raise exception 'bar';
end $$;
+
+prepare q AS VALUES(E'Elephant, kangaroo,\nsquirrel, gorilla', 121,
(279./278.)::text, 0.1111, repeat('Hello ', 50))
+ , (E'goat, rhinoceros,\nmonkey, ape', 11121, (1279./1278.)::text, 5.1111,
repeat('cigar from nicaragua ', 20))
+ , (E'donkey, cow, horse, tit,\neagle, whale,\naligator,
pelican,\ngrasshoper\npig\n\tbat', 14351, (12345./245.)::text, 345.11,
repeat('camfire ', 20));
+
+\pset format aligned
+\pset linestyle rst
+execute q;
+\pset linestyle markdown
+execute q;
+\pset format wrapped
+\pset linestyle rst
+execute q;
+\pset linestyle markdown
+execute q;
+deallocate q;
--
Sent via pgsql-hackers mailing list ([email protected])
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers