Use a comment to add metadata to a table or to a column. A comment is free text. It can give a description, a unit, a source, a license or a contact. A comment changes neither the data nor the schema. Beacon stores the comment with the table, so it survives a restart.
sql
COMMENT ON TABLE ctd IS 'CTD casts in the North Sea, 2024. Source: RV Pelagia. License: CC-BY 4.0';COMMENT ON COLUMN ctd.depth IS 'Depth below the sea surface. Unit: m';COMMENT ON COLUMN ctd.temp IS 'Sea water temperature (ITS-90). Unit: degC';
The users of the table then read the comments in the table schema. They see what each column holds without access to the source files.
The Flight SQL schema of a table holds the comments. With ADBC in Python:
python
import adbc_driver_flightsql.dbapi as flight_sqlwith flight_sql.connect( "grpc://localhost:32011", db_kwargs={"username": "admin", "password": "securepassword"},) as conn: schema = conn.adbc_get_table_schema("ctd") print(schema.metadata[b"comment"]) for field in schema: print(field.name, (field.metadata or {}).get(b"comment"))
A file of an external table can add or delete a column. Beacon then ignores the comment of the deleted column. The comment shows again when the column comes back.
The admin API reads and writes all comments of one table as one JSON document. Use it to copy the comments to another table, or to keep them in a file under version control:
Request
Effect
GET /api/admin/table-comments/{table}
Returns the comments.
PUT /api/admin/table-comments/{table}
Replaces all comments. Send {} to delete them.
DELETE /api/admin/table-comments/{table}
Deletes all comments.
json
{ "table": "CTD casts in the North Sea, 2024. Source: RV Pelagia. License: CC-BY 4.0", "columns": { "depth": "Depth below the sea surface. Unit: m", "temp": "Sea water temperature (ITS-90). Unit: degC" }}
PUT checks each column before it writes. An unknown column gives 400 Bad Request and changes nothing.
COMMENT ON
Use a comment to add metadata to a table or to a column. A comment is free text. It can give a description, a unit, a source, a license or a contact. A comment changes neither the data nor the schema. Beacon stores the comment with the table, so it survives a restart.
The users of the table then read the comments in the table schema. They see what each column holds without access to the source files.
Syntax
IS NULLdeletes the comment. An empty text''also deletes it.IF EXISTSgives no error when the table does not exist.COMMENT ON COLUMNchecks that the column exists. An unknown column gives an error.Only the super-user can set a comment. Send the statement over any SQL interface, for example
POST /api/queryor Arrow Flight SQL.Which tables take a comment
COMMENT ON TABLEfor the view.information_schema,beacon.systemand an attached catalogOnly tables in the default schema
beacon.publictake comments.Write useful comments
A comment has no fixed format. Use the same form in all your tables, so that a person or a script can find each fact:
Unit: degC.Quality flag (SeaDataNet L20): 1 good, 4 bad.A view can carry its own comments. Use it to describe a subset of a table:
Read the comments
Beacon puts each comment into the Arrow schema of the table, under the metadata key
comment:A Beacon comment replaces a
commentkey that the file format already gives.Over HTTP
GET /api/table-schemareturns the schema with the comments. Each user who can read the table can read its comments:The response, shortened:
GET /api/tables-with-schemagives the same metadata for each table.Over Arrow Flight SQL
The Flight SQL schema of a table holds the comments. With ADBC in Python:
With SQL
The super-user can list every comment:
column_nameisNULLfor a table comment. This table also shows the comment of a column that no longer exists.Where the comments do not show
SELECTgives the data only, also in the Arrow and Parquet output formats. Read the comments from the table schema.DESCRIBE <table>shows the column names and types only.SHOW CREATE TABLEshows the statement that created the table, without the comments. Save yourCOMMENT ONstatements with your other DDL.Names keep their case
Beacon keeps the case of every identifier.
COMMENT ON COLUMN ctd.Depthnames the columnDepth, notdepth. See Identifiers & Case.IS NULLdoes not check that the column exists. You can thus delete the comment of a column that no longer exists.Comments follow the schema
ALTER TABLE ... RENAME COLUMN a TO bamoves tob.ALTER TABLE ... DROP COLUMN aa.DROP TABLEREFRESHof a materialized viewA file of an external table can add or delete a column. Beacon then ignores the comment of the deleted column. The comment shows again when the column comes back.
Admin API
The admin API reads and writes all comments of one table as one JSON document. Use it to copy the comments to another table, or to keep them in a file under version control:
GET /api/admin/table-comments/{table}PUT /api/admin/table-comments/{table}{}to delete them.DELETE /api/admin/table-comments/{table}PUTchecks each column before it writes. An unknown column gives400 Bad Requestand changes nothing.Replace presets with views
Beacon no longer has table extensions or presets. Use a view with a comment for a named filter set. See the example in Write useful comments.