A command-line tool that runs PostgreSQL queries and outputs results directly as CSV format.
psql2csv is a lightweight command-line utility that exports PostgreSQL query results directly to CSV files. It wraps the standard psql interface to provide CSV-specific formatting options like custom delimiters, quoting, and encoding while maintaining compatibility with existing psql workflows. It solves the problem of cleanly converting SQL query outputs into CSV format for data export, reporting, or integration with other tools.
Database administrators, data analysts, and developers who regularly export data from PostgreSQL databases for reporting, data migration, or integration with spreadsheet applications like Excel.
Developers choose psql2csv over manual CSV export methods because it simplifies the process with dedicated CSV formatting options, supports parameterized queries via psql variables, and integrates seamlessly into existing command-line workflows without requiring additional database drivers or complex setup.
Run a query in psql and output the result as CSV.
Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.
Accepts queries from STDIN, files, or command-line arguments, enabling seamless integration into scripts and Unix pipelines, as shown in the usage examples.
Offers configurable delimiters, quote characters, null representations, and encoding (e.g., latin1 for Excel), providing precise control over output format for tool compatibility.
Leverages psql's variable system for dynamic queries, allowing parameterization without modifying SQL files, as demonstrated in the advanced usage section.
Allows setting timezone and search_path before queries, ensuring consistent output for time-sensitive or schema-dependent data exports.
Provides a preview of the COPY statement without execution, useful for debugging and validating CSV output formatting before actual data export.
Requires psql and a PostgreSQL database connection, making it unsuitable for multi-database environments or users without PostgreSQL installed.
Only supports CSV export, lacking built-in options for other common formats like JSON, XML, or direct Excel files, which may require additional tools.
Focuses solely on formatting query results as CSV without features for data cleaning, filtering, or aggregation, necessitating separate preprocessing steps.