NAMEDATALEN

A constant which defines the maximum length of database identifiers

NAMEDATALEN is a constant which defines the maximum length (in single byte characters) of database identifiers such as the names of databases, tables, columns etc. This value includes a trailing zero byte, meaning the actual maximum length is NAMEDATALEN - 1.

The value has been 64 since PostgreSQL 7.3 (commit 46bb23ac). Prior to that it was 32.

NAMEDATALEN and ENUM

As well as database identifiers, the maximum length of ENUM labels is also limited to NAMEDATALEN - 1 bytes.

Source code

NAMEDATALEN is defined in src/include/pg_config_manual.h as:

/*
 * Maximum length for identifiers (e.g. table names, column names,
 * function names).  Names actually are limited to one less byte than this,
 * because the length must include a trailing zero byte.
 *
 * Changing this requires an initdb.
 */
#define NAMEDATALEN 64

Notes

This 2017 pgsql-hackers thread: Revisiting NAMEDATALEN contains some insights into why it's unlikely NAMEDATALEN will be extended in the future and discusses the (in)feasibility of making it a configurable parameter.

Categories

DDL, PostgreSQL internals