I'm planning to use prefixes for a series of database names and need to make sure I don't run into a length limit. What length of table names does PostgreSQL support?
Asked
Active
Viewed 1.6k times
31
-
3If in doubt, read the manual: http://www.postgresql.org/docs/current/static/sql-syntax-lexical.html#SQL-SYNTAX-IDENTIFIERS – Jan 09 '15 at 17:31
-
1Does this answer your question? [Maximum characters in labels (table names, columns etc)](https://stackoverflow.com/questions/8213127/maximum-characters-in-labels-table-names-columns-etc) – Vadzim Aug 23 '21 at 15:49
1 Answers
57
According to the PostgreSQL documentation:
identifiers…identify names of tables, columns, or other database objects.…
The system uses no more than
NAMEDATALEN-1
bytes of an identifier; longer names can be written in commands, but they will be truncated. By default,NAMEDATALEN
is 64 so the maximum identifier length is 63 bytes.
You can see this limit using the query suggested by this comment: SELECT length(repeat('xyzzy', 100)::NAME);
creates a 500-character string and casts it to PostgreSQL's NAME
type, then checks the length. The result is 63
.