diff options
author | Alvaro Herrera <alvherre@alvh.no-ip.org> | 2016-04-08 20:23:18 -0300 |
---|---|---|
committer | Alvaro Herrera <alvherre@alvh.no-ip.org> | 2016-04-08 20:23:18 -0300 |
commit | c09b18f21c52cbcf8718d6c267c84fcfea3739a9 (patch) | |
tree | 14ae5d520050d3302c8ecae141a2deda7c17a962 /src/bin/psql/common.c | |
parent | 279d86afdbed550425bc9d1327ade2dc0028ad33 (diff) | |
download | postgresql-c09b18f21c52cbcf8718d6c267c84fcfea3739a9.tar.gz postgresql-c09b18f21c52cbcf8718d6c267c84fcfea3739a9.zip |
Support \crosstabview in psql
\crosstabview is a completely different way to display results from a
query: instead of a vertical display of rows, the data values are placed
in a grid where the column and row headers come from the data itself,
similar to a spreadsheet.
The sort order of the horizontal header can be specified by using
another column in the query, and the vertical header determines its
ordering from the order in which they appear in the query.
This only allows displaying a single value in each cell. If more than
one value correspond to the same cell, an error is thrown. Merging of
values can be done in the query itself, if necessary. This may be
revisited in the future.
Author: Daniel Verité
Reviewed-by: Pavel Stehule, Dean Rasheed
Diffstat (limited to 'src/bin/psql/common.c')
-rw-r--r-- | src/bin/psql/common.c | 26 |
1 files changed, 24 insertions, 2 deletions
diff --git a/src/bin/psql/common.c b/src/bin/psql/common.c index df3441cc750..437cb568234 100644 --- a/src/bin/psql/common.c +++ b/src/bin/psql/common.c @@ -23,6 +23,7 @@ #include "settings.h" #include "command.h" #include "copy.h" +#include "crosstabview.h" #include "fe_utils/mbprint.h" @@ -1064,6 +1065,8 @@ PrintQueryResults(PGresult *results) success = StoreQueryTuple(results); else if (pset.gexec_flag) success = ExecQueryTuples(results); + else if (pset.crosstab_flag) + success = PrintResultsInCrosstab(results); else success = PrintQueryTuples(results); /* if it's INSERT/UPDATE/DELETE RETURNING, also print status */ @@ -1213,7 +1216,8 @@ SendQuery(const char *query) } } - if (pset.fetch_count <= 0 || pset.gexec_flag || !is_select_command(query)) + if (pset.fetch_count <= 0 || pset.gexec_flag || + pset.crosstab_flag || !is_select_command(query)) { /* Default fetch-it-all-and-print mode */ instr_time before, @@ -1356,6 +1360,24 @@ sendquery_cleanup: /* reset \gexec trigger */ pset.gexec_flag = false; + /* reset \crosstabview trigger */ + pset.crosstab_flag = false; + if (pset.ctv_col_V) + { + free(pset.ctv_col_V); + pset.ctv_col_V = NULL; + } + if (pset.ctv_col_H) + { + free(pset.ctv_col_H); + pset.ctv_col_H = NULL; + } + if (pset.ctv_col_D) + { + free(pset.ctv_col_D); + pset.ctv_col_D = NULL; + } + return OK; } @@ -1501,7 +1523,7 @@ ExecQueryUsingCursor(const char *query, double *elapsed_msec) break; } - /* Note we do not deal with \gexec mode here */ + /* Note we do not deal with \gexec or \crosstabview modes here */ ntuples = PQntuples(results); |