Subject | Re: [firebird-support] Zero prefix results in primary key constraint violation |
---|---|
Author | Vlad Khorsun |
Post date | 2009-02-10T07:45:12Z |
> I am executing the following SQL code:Per SQL standard trailing blanks are not accounted at strings comparison. I.e. 'a' == 'a '.
>
> CREATE DATABASE 'keytest.fdb' user 'sysdba' password 'masterkey';
>
> CREATE TABLE test
> (
> Id VARCHAR(16) CHARACTER SET OCTETS NOT NULL,
> PRIMARY KEY (Id)
> );
>
> COMMIT;
>
> INSERT INTO test VALUES (ASCII_CHAR(1));
> INSERT INTO test VALUES (ASCII_CHAR(1) || ASCII_CHAR(0));
>
> The second INSERT gives me a:
>
> Statement failed, SQLCODE = -803
> violation of PRIMARY or UNIQUE KEY constraint "INTEG_2" on table "TEST"
>
> Why is that? The octet strings 01hex and 0100hex are clearly two
> different keys.
Character set OCTETS have defined 0x00 as blank character, so {0x01} == {0x01, 0x00}
Regards,
Vlad