I think I first touched PostgreSQL in 1998 or 1999. It has been a long time, but PostgreSQL keeps inspiring me. I still keep finding cool features which have most likely been around for 15 years or more. Recently, I noticed by coincidence that psql can produce perfect LaTeX code. How cool is that? It's so cool that I decided to share my happiness with people reading my blog.
Here's some test data:
1 2 3 4 5 6 7 8 9 10 |
test=# CREATE TABLE cool_feature (a int, b int); CREATE TABLE test=# INSERT INTO cool_feature VALUES (1, 2), (3, 4); INSERT 0 2 test=# TABLE cool_feature; a | b ---+--- 1 | 2 3 | 4 (2 rows) |
Making psql produce LaTeX is really simple:
1 2 |
test=# pset format latex Output format is latex. |
From now on the output will be returned in LaTeX format:
1 2 3 4 5 6 7 8 9 |
test=# TABLE cool_feature; begin{tabular}{r | r} textit{a} & textit{b} \ hline 1 & 2 \ 3 & 4 \ end{tabular} noindent (2 rows) \ |
This is even true for backslash commands:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
test=# \d begin{center} List of relations end{center} begin{tabular}{l | l | l | l} textit{Schema} & textit{Name} & textit{Type} & textit{Owner} \ hline public & cool_feature & table & hs \ public & pg_stat_statements & view & hs \ public & pgbench_accounts & table & hs \ public & pgbench_branches & table & hs \ public & pgbench_history & table & hs \ public & pgbench_tellers & table & hs \ end{tabular} noindent (6 rows) \ |
PostgreSQL can also produce a variety of other formats, which might be useful to some people: aligned, asciidoc, html, latex, latex-longtable, troff-ms, unaligned, and wrapped.
Find out more about cool psql tricks - read Julian Markwort's blog about using psql to automate repeated tasks: gexec in psql for poweruser practice.
In order to receive regular updates on important changes in PostgreSQL, subscribe to our newsletter, or follow us on Facebook or LinkedIn.
+43 (0) 2622 93022-0
office@cybertec.at
You are currently viewing a placeholder content from Facebook. To access the actual content, click the button below. Please note that doing so will share data with third-party providers.
More InformationYou are currently viewing a placeholder content from X. To access the actual content, click the button below. Please note that doing so will share data with third-party providers.
More Information
where is the tools?
These are built-in tools:
https://www.postgresql.org/docs/current/app-psql.html
https://www.postgresql.org/docs/12/pgbench.html