Skip to content

Feature: Native CSV output format (--csv) #620

@dlevy-msft-sql

Description

@dlevy-msft-sql

Summary

Add a --csv flag to output query results in native CSV format.

Use Case

  • Export data directly to CSV without needing to set column separator and parse manually
  • Integration with data analysis tools (Excel, pandas, etc.)
  • Scripting and automation pipelines

Proposed Syntax

sqlcmd -S server -Q "SELECT * FROM users" --csv

Example Output

id,name,email
1,Alice,alice@example.com
2,Bob,bob@example.com

Features

  • Proper handling of values containing commas (quote wrapping)
  • Proper handling of values containing quotes (escaping)
  • Optional header row (controlled by existing -h flag)
  • UTF-8 encoding by default

Implementation Notes

  • Could leverage existing formatter infrastructure in pkg/sqlcmd/formatter.go
  • Consider using Go's standard encoding/csv package for proper RFC 4180 compliance

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions