Skip to content

db.columns: added format=list and format=csv#6971

Merged
petrasovaa merged 20 commits into
OSGeo:mainfrom
gulshan-123:db.columns_csv_list
Jan 30, 2026
Merged

db.columns: added format=list and format=csv#6971
petrasovaa merged 20 commits into
OSGeo:mainfrom
gulshan-123:db.columns_csv_list

Conversation

@gulshan-123
Copy link
Copy Markdown
Contributor

@gulshan-123 gulshan-123 commented Jan 26, 2026

Fixes #6072

Added an option separator to db.columns which will be field separator in case of CSV and LIST format, but will be error in JSON and PLAIN format.

Also, I have rearranged declaration of some variables, so that to avoid re-declaring in each switch case block.

grass > db.columns zipcodes format=list -e separator=';'
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

default separator=newline

grass > db.columns zipcodes format=list
cat
OBJECTID
WAKE_ZIPCO
PERIMETER
ZIPCODE_
ZIPCODE_ID
ZIPNAME
ZIPNUM
ZIPCODE
NAME
SHAPE_Leng
SHAPE_Area
grass > db.columns zipcodes format=list separator=';'
cat;OBJECTID;WAKE_ZIPCO;PERIMETER;ZIPCODE_;ZIPCODE_ID;ZIPNAME;ZIPNUM;ZIPCODE;NAME;SHAPE_Leng;SHAPE_Area

default separator=newline

grass > db.columns zipcodes format=list -e
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

default separator=comma

grass > db.columns zipcodes format=csv -e
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
grass > db.columns zipcodes format=csv -e separator='\t'
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

separator is of no effect

grass > db.columns zipcodes format=csv separator='\t'
name
cat
OBJECTID
WAKE_ZIPCO
PERIMETER
ZIPCODE_
ZIPCODE_ID
ZIPNAME
ZIPNUM
ZIPCODE
NAME
SHAPE_Leng
SHAPE_Area

In case of format=csv and without -e: the separator has no role, should we give warning to user?

TODO:

  • examples
  • tests

@github-actions github-actions Bot added C Related code is in C database Related to database management module labels Jan 26, 2026
@petrasovaa
Copy link
Copy Markdown
Contributor

In case of format=csv and without -e: the separator has no role, should we give warning to user?

I don't think so, it's valid and harmless. The issue is that csv format makes really sense only together with the -e flag, so we could potentially restrict the user to use the csv format only with the -e flag, or automatically turn on the -e flag with csv. At this point, just leave it the way you have it, it's consistent behavior that way, just maybe don't show example of csv without -e in the documentation.

@gulshan-123
Copy link
Copy Markdown
Contributor Author

Thank you!

just leave it the way you have it, it's consistent behavior that way

Ok

I have now added the tests and docs. I have included examples of list and csv format with -e only, as I think this is what user will use with these formats. As without -e flag, list, csv and plain gives almost same output except header name.

@github-actions github-actions Bot added Python Related code is in Python docs markdown Related to markdown, markdown files tests Related to Test Suite labels Jan 27, 2026
Comment thread db/db.columns/db.columns.md Outdated
Comment thread db/db.columns/db.columns.md Outdated
Comment thread db/db.columns/db.columns.md Outdated
Comment thread db/db.columns/testsuite/test_db_columns.py
@gulshan-123
Copy link
Copy Markdown
Contributor Author

Thank you for the review!

I have added a new heading in the doc with Other supported output formats where I have included CSV and List output format.

I have renamed the file name too. And removed some redundant docs.

Copy link
Copy Markdown
Contributor

@petrasovaa petrasovaa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I took the liberty to update and reorganize the documentation. Ready for merge, thank you!

@petrasovaa petrasovaa enabled auto-merge (squash) January 30, 2026 20:56
@petrasovaa petrasovaa merged commit 5dd1f90 into OSGeo:main Jan 30, 2026
27 checks passed
@github-actions github-actions Bot added this to the 8.5.0 milestone Jan 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

C Related code is in C database Related to database management docs markdown Related to markdown, markdown files module Python Related code is in Python tests Related to Test Suite

Projects

None yet

Development

Successfully merging this pull request may close these issues.

db.columns: Output column metadata, not just names

2 participants