CREATE TEMP TABLE my_data AS SELECT * FROM ggsql:penguins LIMIT 5
TABULATE * FROM my_data
LABEL bill_len => 'Bill length', bill_dep => 'Bill depth'Define different titles with LABEL
This page is about the TABULATE usage of the LABEL clause. For the VISUALISE usage, see this page.
The LABEL clause is a straightforward clause allowing you to override the default naming of column labels, spans, (sub)titles and captions. Unlike VISUALISE’s usage, there is no automatic labelling: a column with no label keeps its name as header.
Clause syntax
The LABEL clause requires a comma-separated list of key-value pairs
LABEL <column/title> => <string/null>, ...On the left hand side of the arrow, the following keys can be used:
- Column names as they occur in the data
- Reserved keywords for special labels:
titleas the main titlesubtitleas the subtitlecaptionas the table caption
- Spanner IDs declared by
SPANclauses.
On the right hand side of the arrow, one can use a string to give new label, or null to hide the label.
Rich text
The support of rich text in tables is planned but not yet implemented.
Examples
Unlike using aliases in TABULATE, the LABEL clause lets you change column labels without changing column order
Hiding labels.
TABULATE * FROM my_data
LABEL island => null, species => nullAdding titles to a table.
TABULATE * FROM my_data
LABEL
title => 'Penguins!',
subtitle => 'Structural size measurements',
caption => 'Source: Palmer station, Antarctica'| Penguins! | |||||||
|---|---|---|---|---|---|---|---|
| Structural size measurements | |||||||
When column names and reserved keywords compete for a label, the reserved keyword wins.
-- data has column named 'title'
CREATE TEMP TABLE title_data AS
SELECT * FROM (VALUES (1, 'a'), (2, 'b'), (3, 'c')) AS t(id, title)
TABULATE * FROM title_data
LABEL
title => 'Overrules column'| Overrules column | |
|---|---|
You can target an aliased column instead.
TABULATE *, title AS title_col FROM title_data
LABEL
title => 'Main title',
title_col => 'Column title'| Main title | |
|---|---|