Search code examples
database-designprimary-keyfirebird

What is the maximum size of a primary key in Firebird?


I need to set a Varchar(255) field as the primary key of a database table in Firebird 2.1.

I get error messages saying that the field size is too large. I'm using UTF8 as my character set and the default page size of 4096.

Is it possible to do this in Firebird? I need to ensure that this column is unique.


Solution

  • As explained the maximum key size is 1/4 of the page size, but from Firebird Language Reference (here), the maximum indexable string length in bytes is 9 less than the maximum key length. And UTF8 in Firebird is stored internally as 4 Bytes/char.

    Thus the maximum length for a UTF8 in a 4096 page sized database is 253 chars (4096/4 -9 = 1024 -9 = 1015 limiting to 253*4=1012). So, if you want a bigger string, you need a bigger page sized database (even if you are using Firebird 2.5.x).