31

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?

rep
  • 1,546
  • 1
  • 12
  • 19
  • 3
    If 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
  • 1
    Does 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 Answers1

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.

Community
  • 1
  • 1
rep
  • 1,546
  • 1
  • 12
  • 19