pg_csv
pg_csv
pg_csv : Flexible CSV processing for Postgres
Overview
| ID | Extension | Package | Version | Category | License | Language |
|---|---|---|---|---|---|---|
| 4760 | pg_csv | pg_csv | 1.0.1 | FUNC | MIT | C |
| Attribute | Has Binary | Has Library | Need Load | Has DDL | Relocatable | Trusted |
|---|---|---|---|---|---|---|
--s-dtr | No | Yes | No | Yes | yes | yes |
| Relationships | |
|---|---|
| See Also | aggs_for_vecs first_last_agg arraymath intarray |
Packages
| Type | Repo | Version | PG Major Compatibility | Package Pattern | Dependencies |
|---|---|---|---|---|---|
| EXT | PGDG | 1.0.1 | 18 17 16 15 14 | pg_csv | - |
| RPM | PGDG | 1.0.1 | 18 17 16 15 14 | pg_csv_$v | - |
| DEB | PIGSTY | 1.0.1 | 18 17 16 15 14 | postgresql-$v-pg-csv | - |
| Linux / PG | PG18 | PG17 | PG16 | PG15 | PG14 |
|---|---|---|---|---|---|
el8.x86_64 | PGDG 1.0.1 | PGDG 1.0.1 | PGDG 1.0.1 | PGDG 1.0.1 | PGDG 1.0.1 |
el8.aarch64 | PGDG 1.0.1 | PGDG 1.0.1 | PGDG 1.0.1 | PGDG 1.0.1 | PGDG 1.0.1 |
el9.x86_64 | PGDG 1.0.1 | PGDG 1.0.1 | PGDG 1.0.1 | PGDG 1.0.1 | PGDG 1.0.1 |
el9.aarch64 | PGDG 1.0.1 | PGDG 1.0.1 | PGDG 1.0.1 | PGDG 1.0.1 | PGDG 1.0.1 |
el10.x86_64 | PGDG 1.0.1 | PGDG 1.0.1 | PGDG 1.0.1 | PGDG 1.0.1 | PGDG 1.0.1 |
el10.aarch64 | PGDG 1.0.1 | PGDG 1.0.1 | PGDG 1.0.1 | PGDG 1.0.1 | PGDG 1.0.1 |
d12.x86_64 | PGDG 1.0.2 | PGDG 1.0.2 | PGDG 1.0.2 | PGDG 1.0.2 | PGDG 1.0.2 |
d12.aarch64 | PGDG 1.0.2 | PGDG 1.0.2 | PGDG 1.0.2 | PGDG 1.0.2 | PGDG 1.0.2 |
d13.x86_64 | PGDG 1.0.2 | PGDG 1.0.2 | PGDG 1.0.2 | PGDG 1.0.2 | PGDG 1.0.2 |
d13.aarch64 | PGDG 1.0.2 | PGDG 1.0.2 | PGDG 1.0.2 | PGDG 1.0.2 | PGDG 1.0.2 |
u22.x86_64 | PGDG 1.0.2 | PGDG 1.0.2 | PGDG 1.0.2 | PGDG 1.0.2 | PGDG 1.0.2 |
u22.aarch64 | PGDG 1.0.2 | PGDG 1.0.2 | PGDG 1.0.2 | PGDG 1.0.2 | PGDG 1.0.2 |
u24.x86_64 | PGDG 1.0.2 | PGDG 1.0.2 | PGDG 1.0.2 | PGDG 1.0.2 | PGDG 1.0.2 |
u24.aarch64 | PGDG 1.0.2 | PGDG 1.0.2 | PGDG 1.0.2 | PGDG 1.0.2 | PGDG 1.0.2 |
Source
pig build pkg pg_csv; # build debInstall
Make sure PGDG repo available:
pig repo add pgdg -u # add pgdg repo and update cacheInstall this extension with pig:
pig install pg_csv; # install via package name, for the active PG version
pig install pg_csv -v 18; # install for PG 18
pig install pg_csv -v 17; # install for PG 17
pig install pg_csv -v 16; # install for PG 16
pig install pg_csv -v 15; # install for PG 15
pig install pg_csv -v 14; # install for PG 14Create this extension with:
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;Last updated on