Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to change Postgres Table Field name limit?

Tags:

postgresql

I want to create a table whose field name is of 100 characters but postgres limit for no of characters is 64 so how to change that limit to 100?

example: Create table Test ( PatientFirstnameLastNameSSNPolicyInsuraceTicketDetailEMRquestionEMR varchar(10) )

This table creation fails as the name exceeds 64 characters

like image 843
Test Avatar asked Jun 10 '11 13:06

Test


People also ask

How do I change the length of a column in PostgreSQL?

How to increase the length of a character varying datatype in Postgres without data loss. Run the following command: alter table TABLE_NAME alter column COLUMN_NAME type character varying(120); This will extend the character varying column field size to 120.

How do you change column constraints in PostgreSQL?

The syntax to modify a column in a table in PostgreSQL (using the ALTER TABLE statement) is: ALTER TABLE table_name ALTER COLUMN column_name TYPE column_definition; table_name. The name of the table to modify.

Can column name have space in PostgreSQL?

It is acceptable to use spaces when you are aliasing a column name. However, it is not generally good practice to use spaces when you are aliasing a table name. The alias_name is only valid within the scope of the SQL statement.

How many columns can a Postgres table have?

PostgreSQL tables are hard-limited to a maximum of 1600 columns.


2 Answers

Actually name's limit is equal to NAMEDATALEN - 1 bytes (not necessarily characters), default value for NAMEDATALEN is 64.

NAMEDATALEN was determined at compile time (in src/include/pg_config_manual.h). You have to recompile PostgreSQL with new NAMEDATALEN limit to make it work.

However think about design and compatibility with other servers with standard 63 bytes limit. It's not common practice to use such long names.

like image 199
Grzegorz Szpetkowski Avatar answered Oct 05 '22 10:10

Grzegorz Szpetkowski


It's because of the special name type (see table 8.5), which is used in pg_catalog. It won't accept anything longer than 63 bytes (plus terminator). There is no workaround.

like image 31
Denis de Bernardy Avatar answered Oct 05 '22 09:10

Denis de Bernardy