Wiki / psql Commands / Output and formatting
\crosstabview
Executes the current query buffer (like \g ) and shows the results in a crosstab grid. The query must return at least three columns. The output column identified by colV becomes a vertical header and the output column identified by colH becomes a ho…
Reading PostgreSQL 18.6.
Description
Executes the current query buffer (like \g ) and shows the results in a crosstab grid. The query must return at least three columns. The output column identified by colV becomes a vertical header and the output column identified by colH becomes a horizontal header. colD identifies the output column to display within the grid. sortcolH identifies an optional sort column for the horizontal header.
- Client
- psql 18.6
- Case-sensitive spelling
- \crosstabview
Usage
\crosstabview [ colV [ colH [ colD [ sortcolH ] ] ] ]Spellings in this manual definition
| Command | Documented suffix modifiers |
|---|---|
| \crosstabview | None listed in this signature |
Manual definition
\crosstabview [colV[colH[colD[sortcolH] ] ] ]-
Executes the current query buffer (like
\g) and shows the results in a crosstab grid. The query must return at least three columns. The output column identified bycolVbecomes a vertical header and the output column identified bycolHbecomes a horizontal header.colDidentifies the output column to display within the grid.sortcolHidentifies an optional sort column for the horizontal header.Each column specification can be a column number (starting at 1) or a column name. The usual SQL case folding and quoting rules apply to column names. If omitted,
colVis taken as column 1 andcolHas column 2.colHmust differ fromcolV. IfcolDis not specified, then there must be exactly three columns in the query result, and the column that is neithercolVnorcolHis taken to becolD.The vertical header, displayed as the leftmost column, contains the values found in column
colV, in the same order as in the query results, but with duplicates removed.The horizontal header, displayed as the first row, contains the values found in column
colH, with duplicates removed. By default, these appear in the same order as in the query results. But if the optionalsortcolHargument is given, it identifies a column whose values must be integer numbers, and the values fromcolHwill appear in the horizontal header sorted according to the correspondingsortcolHvalues.Inside the crosstab grid, for each distinct value
xofcolHand each distinct valueyofcolV, the cell located at the intersection(x,y)contains the value of thecolDcolumn in the query result row for which the value ofcolHisxand the value ofcolVisy. If there is no such row, the cell is empty. If there are multiple such rows, an error is reported.
Related entries
Documentation and source
Source build
- Version
- 18.6
- Build
- https://ftp.postgresql.org/pub/source/v18.6/postgresql-18.6.tar.bz2
- Source fingerprint
ee8d1a3612338fd9adf250730cb640fcc5233b5491337cc00a316a44e3a0b9f8
Compare versions
PostgreSQL 17 → 18: unchanged.
Compares recorded interfaces and attributes. Source fingerprints and build metadata are excluded; an absent sample is not proof of the introduction or removal release.
Related entries
Export JSON · Back to psql Commands · Recorded in PostgreSQL 10 through 20; the first sample is not necessarily its introduction.