Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How long can PostgreSQL table names be?

Tags:

postgresql

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?

like image 545
rep Avatar asked Jan 09 '15 17:01

rep


People also ask

How long can a table name be?

The maximum length of a table name is 64 characters long according to MySQl version 8.0.

What is the maximum length of text in Postgres?

3) PostgreSQL Text Data Type The PostgreSQL Text data type is used to keep the character of infinite length. And it can hold a string with a maximum length of 65,535 bytes.

How long can a database table name be in SQL?

Table names must follow the rules for SQL Server identifiers, and be less than 128 characters.

What is the maximum length of column name in PostgreSQL?

Column names Must be less than the maximum length of 59 characters. Columns that exceed this limit will be rejected by PostgreSQL.


1 Answers

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.

like image 54
rep Avatar answered Oct 21 '22 21:10

rep