views:

163

answers:

2

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.

A: 

According to FirebirdFAQ the maximum key size in Firebird 2.x is one fourth of the page size. If your page size is 4096 bytes your maximum key size is 1024 bytes.
UTF8 varchars reserve a full 32-bits per char even though it may use less space. Thus a varchar(255) in UTF8 is 1020 bytes. I don't know why it's hitting the limit, but anyway I'd increase the page size or try varchar(254).

Douglas Tosi
A: 

just make gstat d:\path\database.fdb

you will get someting like this for your index :

> Index CLIENT_IDX (2) 
>         Depth: 3, leaf buckets: 545, nodes: 138523 
>         Average data length: 10.12, total dup: 13873, max dup: 645 
>         Fill distribution: 
>              0 - 19% = 0 
>             20 - 39% = 0 
>             40 - 59% = 0 
>             60 - 79% = 0 
>             80 - 99% = 545

if Depth is more than 3 : you will have to increase the page size. It is the same as Douglas Tosi say.

You can see this very well in tools like IBExpert full edition or in IBAnalist

Hugues Van Landeghem