Skip to content

colnames

Return column names of a record or composite value

Overview

PackageVersionCategoryLicenseLanguage
colnames1.7.0UTILPostgreSQLC
IDExtensionBinLibLoadCreateTrustRelocSchema
4360colnamesNoYesNoYesNoYes-
Relatedpg_describe describe_resultset get_column pltoolbox hstore

Distribution 1.7.1 retains extension version 1.7.0; colnames(record) returns name[]. No preload or runtime extension dependencies. Upstream release lists PG8.2-17; PG14-18 verified across all 16 PGSTY target platforms.

Version

TypeRepoVersionPG VerPackageDeps
EXTPIGSTY1.7.01817161514colnames-
RPMPIGSTY1.7.11817161514colnames_$v-
DEBPIGSTY1.7.11817161514postgresql-$v-colnames-
OS / PGPG18PG17PG16PG15PG14
el8.x86_64
el8.aarch64
el9.x86_64
el9.aarch64
el10.x86_64
el10.aarch64
d12.x86_64
d12.aarch64
PIGSTY 1.7.1
PIGSTY 1.7.1
PIGSTY 1.7.1
PIGSTY 1.7.1
PIGSTY 1.7.1
d13.x86_64
PIGSTY 1.7.1
PIGSTY 1.7.1
PIGSTY 1.7.1
PIGSTY 1.7.1
PIGSTY 1.7.1
d13.aarch64
PIGSTY 1.7.1
PIGSTY 1.7.1
PIGSTY 1.7.1
PIGSTY 1.7.1
PIGSTY 1.7.1
u22.x86_64
PIGSTY 1.7.1
PIGSTY 1.7.1
PIGSTY 1.7.1
PIGSTY 1.7.1
PIGSTY 1.7.1
u22.aarch64
PIGSTY 1.7.1
PIGSTY 1.7.1
PIGSTY 1.7.1
PIGSTY 1.7.1
PIGSTY 1.7.1
u24.x86_64
PIGSTY 1.7.1
PIGSTY 1.7.1
PIGSTY 1.7.1
PIGSTY 1.7.1
PIGSTY 1.7.1
u24.aarch64
PIGSTY 1.7.1
PIGSTY 1.7.1
PIGSTY 1.7.1
PIGSTY 1.7.1
PIGSTY 1.7.1
u26.x86_64
u26.aarch64
PIGSTY 1.7.1
PIGSTY 1.7.1
PIGSTY 1.7.1
PIGSTY 1.7.1
PIGSTY 1.7.1

Build

You can build the RPM / DEB packages for colnames using pig build:

pig build pkg colnames         # build RPM / DEB packages

Install

You can install colnames directly. First, make sure the PGDG and PIGSTY repositories are added and enabled:

pig repo add pgsql -u          # Add repo and update cache

Install the extension using pig or apt/yum/dnf:

Install
pig install colnames;          # Install for current active PG version
pig
pig ext install -y colnames -v 18  # PG 18
pig ext install -y colnames -v 17  # PG 17
pig ext install -y colnames -v 16  # PG 16
pig ext install -y colnames -v 15  # PG 15
pig ext install -y colnames -v 14  # PG 14
dnf
dnf install -y colnames_18       # PG 18
dnf install -y colnames_17       # PG 17
dnf install -y colnames_16       # PG 16
dnf install -y colnames_15       # PG 15
dnf install -y colnames_14       # PG 14
apt
apt install -y postgresql-18-colnames   # PG 18
apt install -y postgresql-17-colnames   # PG 17
apt install -y postgresql-16-colnames   # PG 16
apt install -y postgresql-15-colnames   # PG 15
apt install -y postgresql-14-colnames   # PG 14

Create Extension:

CREATE EXTENSION colnames;

Usage

Sources:

colnames provides colnames(record), returning the input record’s field names as a name[]. Use it in generic triggers or dynamic SQL helpers that need a composite value’s structure without converting its values to JSON. Distribution version 1.7.1 retains extension version 1.7.0.

Core Workflow

CREATE EXTENSION colnames;

SELECT colnames(ROW(1, 'foo', 458.0));
SELECT colnames(t)
FROM (SELECT 1 AS id, 'Ada'::text AS name) AS t;

CREATE TYPE contact AS (id integer, name text);
SELECT colnames(NULL::contact);

The three calls return {f1,f2,f3}, {id,name}, and {id,name} respectively. Anonymous rows receive generated names; named rows preserve their attribute names. A typed null works because its composite type supplies the descriptor. An untyped null does not identify a composite type.

Function Behavior

colnames(record) returns name[], is STABLE, and is deliberately not STRICT. It preserves column order and quoted identifier spelling, omits dropped columns, and returns an empty array for an empty composite type. It reads the row descriptor rather than table data.

Operational Notes

The extension has no runtime extension dependencies and needs no preload or restart. Its C library loads when the function is called. Creating the extension requires a superuser because the control file does not mark it trusted. It is relocatable and can be installed in a chosen schema or moved with ALTER EXTENSION colnames SET SCHEMA.

Release 1.7.1 documents PostgreSQL 8.2–17 compatibility. The PGSTY package targets PostgreSQL 14–18; PostgreSQL 18 acceptance comes from package and regression testing rather than that release’s compatibility statement.

PostgreSQL 9.3 and later also offer row_to_json with json_object_keys as a pure SQL alternative. If discovered names are used in dynamic SQL, quote identifiers and keep values parameterized.

Was this page helpful?