Skip to content

db.columns

List all columns for a given table.

db.columns [-e] table=name [driver=name] [database=name] [separator=character] format=name [--verbose] [--quiet] [--qq] [--ui]

Example:

sh db.columns table=name format=plain

grass.script.parse_command("db.columns", table, driver="sqlite", database="\(GISDBASE/\)LOCATION_NAME/$MAPSET/sqlite/sqlite.db", separator=None, format="plain", flags=None, verbose=None, quiet=None, superquiet=None)

Example:

python gs.parse_command("db.columns", table="name", format="json")

grass.tools.Tools.db_columns(table, driver="sqlite", database="\(GISDBASE/\)LOCATION_NAME/$MAPSET/sqlite/sqlite.db", separator=None, format="plain", flags=None, verbose=None, quiet=None, superquiet=None)

Example:

python tools = Tools() tools.db_columns(table="name", format="json")

This grass.tools API is experimental in version 8.5 and expected to be stable in version 8.6.

Parameters

table=name [required]
    Name of attribute table
driver=name
    Name of database driver
    Allowed values: dbf, odbc, ogr, pg, sqlite
    Default: sqlite
database=name
    Name of database
    Default: \(GISDBASE/\)LOCATION_NAME/$MAPSET/sqlite/sqlite.db
separator=character
    Field separator
    Special characters: pipe, comma, space, tab, newline
format=name [required]
    Output format
    Allowed values: plain, csv, json, list
    Default: plain
    plain: Configurable plain text output
    csv: CSV (Comma Separated Values)
    json: JSON (JavaScript Object Notation)
    list: Output in list format
-e
    Print type information about the columns
    Print the name and the type of all the columns for a given table.
--help
    Print usage summary
--verbose
    Verbose module output
--quiet
    Quiet module output
--qq
    Very quiet module output
--ui
    Force launching GUI dialog

table : str, required
    Name of attribute table
    Used as: input, dbtable, name
driver : str, optional
    Name of database driver
    Used as: input, dbdriver, name
    Allowed values: dbf, odbc, ogr, pg, sqlite
    Default: sqlite
database : str, optional
    Name of database
    Used as: input, dbname, name
    Default: \(GISDBASE/\)LOCATION_NAME/$MAPSET/sqlite/sqlite.db
separator : str, optional
    Field separator
    Special characters: pipe, comma, space, tab, newline
    Used as: input, separator, character
format : str, required
    Output format
    Used as: name
    Allowed values: plain, csv, json, list
    plain: Configurable plain text output
    csv: CSV (Comma Separated Values)
    json: JSON (JavaScript Object Notation)
    list: Output in list format
    Default: plain
flags : str, optional
    Allowed values: e
    e
        Print type information about the columns
        Print the name and the type of all the columns for a given table.
verbose : bool, optional
    Verbose module output
    Default: None
quiet : bool, optional
    Quiet module output
    Default: None
superquiet : bool, optional
    Very quiet module output
    Default: None

table : str, required
    Name of attribute table
    Used as: input, dbtable, name
driver : str, optional
    Name of database driver
    Used as: input, dbdriver, name
    Allowed values: dbf, odbc, ogr, pg, sqlite
    Default: sqlite
database : str, optional
    Name of database
    Used as: input, dbname, name
    Default: \(GISDBASE/\)LOCATION_NAME/$MAPSET/sqlite/sqlite.db
separator : str, optional
    Field separator
    Special characters: pipe, comma, space, tab, newline
    Used as: input, separator, character
format : str, required
    Output format
    Used as: name
    Allowed values: plain, csv, json, list
    plain: Configurable plain text output
    csv: CSV (Comma Separated Values)
    json: JSON (JavaScript Object Notation)
    list: Output in list format
    Default: plain
flags : str, optional
    Allowed values: e
    e
        Print type information about the columns
        Print the name and the type of all the columns for a given table.
verbose : bool, optional
    Verbose module output
    Default: None
quiet : bool, optional
    Quiet module output
    Default: None
superquiet : bool, optional
    Very quiet module output
    Default: None

Returns:

result : grass.tools.support.ToolResult | None
If the tool produces text as standard output, a ToolResult object will be returned. Otherwise, None will be returned.

Raises:

grass.tools.ToolError: When the tool ended with an error.

DESCRIPTION

db.columns lists all columns for a given table. Connection to databases are supported through dbf, shp, odbc and pg drivers.

NOTE

If parameters for database connection are already set with db.connect, they are taken as default values and do not need to be specified each time.

EXAMPLES

List columns

List of columns in shell:

sh db.columns table=zipcodes_wake format=list

text cat OBJECTID WAKE_ZIPCO PERIMETER ZIPCODE_ ZIPCODE_ID ZIPNAME ZIPNUM ZIPCODE NAME SHAPE_Leng SHAPE_Area

List of columns in Python:

```python from grass.tools import Tools

columns = Tools().db_columns(table="zipcodes_wake", format="json") print(list(columns)) ```

text ['cat', 'OBJECTID', 'WAKE_ZIPCO', 'PERIMETER', 'ZIPCODE_', 'ZIPCODE_ID', 'ZIPNAME', 'ZIPNUM', 'ZIPCODE', 'NAME', 'SHAPE_Leng', 'SHAPE_Area']

List detailed column information

List column types in plain format:

sh db.columns -e table=zipcodes_wake

text cat: INTEGER OBJECTID: INTEGER WAKE_ZIPCO: DOUBLE PRECISION PERIMETER: DOUBLE PRECISION ZIPCODE_: DOUBLE PRECISION ZIPCODE_ID: DOUBLE PRECISION ZIPNAME: CHARACTER ZIPNUM: DOUBLE PRECISION ZIPCODE: CHARACTER NAME: CHARACTER SHAPE_Leng: DOUBLE PRECISION SHAPE_Area: DOUBLE PRECISION

List column types in JSON format:

sh db.columns -e table=zipcodes_wake format=json

```json [ { "name": "cat", "sql_type": "INTEGER", "is_number": true }, { "name": "OBJECTID", "sql_type": "INTEGER", "is_number": true }, { "name": "WAKE_ZIPCO", "sql_type": "DOUBLE PRECISION", "is_number": true },

...

] ```

Create an SQL-like column list:

sh db.columns -e table=zipcodes_wake format=list separator=comma

text cat INTEGER,OBJECTID INTEGER,WAKE_ZIPCO DOUBLE PRECISION,PERIMETER DOUBLE PRECISION,ZIPCODE_ DOUBLE PRECISION,ZIPCODE_ID DOUBLE PRECISION,ZIPNAME CHARACTER,ZIPNUM DOUBLE PRECISION,ZIPCODE CHARACTER,NAME CHARACTER,SHAPE_Leng DOUBLE PRECISION,SHAPE_Area DOUBLE PRECISION

List column types in CSV format:

sh db.columns -e table=zipcodes_wake format=csv

text name,sql_type,is_number cat,INTEGER,true OBJECTID,INTEGER,true WAKE_ZIPCO,DOUBLE PRECISION,true PERIMETER,DOUBLE PRECISION,true ZIPCODE_,DOUBLE PRECISION,true ZIPCODE_ID,DOUBLE PRECISION,true ZIPNAME,CHARACTER,false ZIPNUM,DOUBLE PRECISION,true ZIPCODE,CHARACTER,false NAME,CHARACTER,false SHAPE_Leng,DOUBLE PRECISION,true SHAPE_Area,DOUBLE PRECISION,true

List columns of a PostgreSQL attribute table

sh db.columns table=zipcodes_wake driver=pg database=grassdb

If the database parameters are already set, the columns can be listed directly:

sh db.columns table=zipcodes_wake

SEE ALSO

db.connect, db.describe, db.drivers, db.droptable, db.execute, db.login, db.tables, GRASS SQL interface

GRASS SQL interface

AUTHOR

Radim Blazek, ITC-Irst, Trento, Italy

SOURCE CODE

Available at: db.columns source code (history)
Latest change: Saturday Jan 31 03:52:33 2026 in commit 5dd1f90