pg_csv

Flexible CSV processing for Postgres

Overview

PackageVersionCategoryLicenseLanguage
pg_csv1.0.1FUNCMITC
IDExtensionBinLibLoadCreateTrustRelocSchema
4760pg_csvNoYesNoYesYesYes-
Relatedaggs_for_vecs first_last_agg arraymath intarray

Version

TypeRepoVersionPG VerPackageDeps
EXTPGDG1.0.11817161514pg_csv-
RPMPGDG1.0.11817161514pg_csv_$v-
DEBPIGSTY1.0.11817161514postgresql-$v-pg-csv-
OS / PGPG18PG17PG16PG15PG14
el8.x86_64
el8.aarch64
el9.x86_64
el9.aarch64
el10.x86_64
el10.aarch64
d12.x86_64
d12.aarch64
d13.x86_64
d13.aarch64
u22.x86_64
u22.aarch64
u24.x86_64
u24.aarch64

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

pg_csv: flexible CSV processing as aggregate functions

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

FunctionDescription
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;

Last Modified 2026-03-12: add pg extension catalog (95749bf)