pg_csv
Flexible CSV processing for Postgres
Repository
PostgREST/pg_csv
https://github.com/PostgREST/pg_csv
Source
pg_csv-1.0.1.tar.gz
pg_csv-1.0.1.tar.gz
Overview
| Package | Version | Category | License | Language |
|---|---|---|---|---|
pg_csv | 1.0.1 | FUNC | MIT | C |
| ID | Extension | Bin | Lib | Load | Create | Trust | Reloc | Schema |
|---|---|---|---|---|---|---|---|---|
| 4760 | pg_csv | No | Yes | No | Yes | Yes | Yes | - |
| Related | aggs_for_vecs first_last_agg arraymath intarray |
|---|
Version
| Type | Repo | Version | PG Ver | Package | Deps |
|---|---|---|---|---|---|
| EXT | PGDG | 1.0.1 | 1817161514 | pg_csv | - |
| RPM | PGDG | 1.0.1 | 1817161514 | pg_csv_$v | - |
| DEB | PIGSTY | 1.0.1 | 1817161514 | postgresql-$v-pg-csv | - |
Build
You can build the DEB packages for pg_csv using pig build:
pig build pkg pg_csv # build DEB packages
Install
You can install pg_csv directly. First, make sure the PGDG repository is added and enabled:
pig repo add pgdg -u # Add PGDG repo and update cache
Install the extension using pig or apt/yum/dnf:
pig install pg_csv; # Install for current active PG version
pig ext install -y pg_csv -v 18 # PG 18
pig ext install -y pg_csv -v 17 # PG 17
pig ext install -y pg_csv -v 16 # PG 16
pig ext install -y pg_csv -v 15 # PG 15
pig ext install -y pg_csv -v 14 # PG 14
dnf install -y pg_csv_18 # PG 18
dnf install -y pg_csv_17 # PG 17
dnf install -y pg_csv_16 # PG 16
dnf install -y pg_csv_15 # PG 15
dnf install -y pg_csv_14 # PG 14
apt install -y postgresql-18-pg-csv # PG 18
apt install -y postgresql-17-pg-csv # PG 17
apt install -y postgresql-16-pg-csv # PG 16
apt install -y postgresql-15-pg-csv # PG 15
apt install -y postgresql-14-pg-csv # PG 14
Create Extension:
CREATE EXTENSION pg_csv;
Usage
Provides a CSV aggregate that composes with SQL expressions, unlike COPY which requires a special protocol. RFC 4180 compliant with proper quoting.
CREATE EXTENSION pg_csv;
Functions
| Function | Description |
|---|---|
csv_agg(record) | Aggregate rows into CSV text with headers |
csv_agg(record, csv_options(...)) | Aggregate with custom options |
csv_options(delimiter, bom, header, nullstr) | Configure CSV output options |
Examples
CREATE TABLE projects AS SELECT * FROM (VALUES
(1, 'Death Star OS', 1),
(2, 'Windows 95 Rebooted', 1),
(3, 'Project "Comma,Please"', 2)
) AS _(id, name, client_id);
-- Basic CSV output
SELECT csv_agg(x) FROM projects x;
-- id,name,client_id
-- 1,Death Star OS,1
-- 2,Windows 95 Rebooted,1
-- 3,"Project ""Comma,Please""",2
-- Pipe-separated values
SELECT csv_agg(x, csv_options(delimiter := '|')) FROM projects x;
-- Tab-separated values
SELECT csv_agg(x, csv_options(delimiter := E'\t')) FROM projects x;
-- With BOM for Excel compatibility
SELECT csv_agg(x, csv_options(bom := true)) FROM projects x;
Feedback
Was this page helpful?
Thanks for the feedback! Please let us know how we can improve.
Sorry to hear that. Please let us know how we can improve.