Як помістити 29 символів у VARCHAR(10)
Firebird Friday Joke #6 (з https://t.me/firebirdsql)
Старий, але все ще гарний жарт: з багатобайтовими наборами символів можна вставити більше символів, ніж заявлено. Вивчайте Unicode! :)
Насолоджуйтесь!
C:\HQbird\Firebird25.in>isql
Use CONNECT or CREATE DATABASE to specify a database
SQL> create database "c:\databases\test1.fdb" user "SYSDBA" password "masterkey";
SQL> create table t2(v1 varchar(10) character set UNICODE_FSS);
SQL> insert into t2(v1) values('12345678901');
SQL> insert into t2(v1) values('123456789012');
SQL> insert into t2(v1) values('1234567890123');
SQL> insert into t2(v1) values('12345678901234');
SQL> insert into t2(v1) values('123456789012345');
SQL> insert into t2(v1) values('1234567890123456');
SQL> insert into t2(v1) values('12345678901234567');
SQL> insert into t2(v1) values('1234567890123456789101234');
SQL> insert into t2(v1) values('12345678901234567891012345');
SQL> insert into t2(v1) values('123456789012345678910123456');
SQL> insert into t2(v1) values('1234567890123456789101234567');
SQL> insert into t2(v1) values('12345678901234567891012345678');
SQL> insert into t2(v1) values('123456789012345678910123456789'); <--- 29 символів!
SQL> insert into t2(v1) values('1234567890123456789101234567890');
Statement failed, SQLSTATE = 22001
arithmetic exception, numeric overflow, or string truncation
-string right truncation
SQL> create table t3(v1 varchar(10) character set UTF8);
SQL> insert into t2(v1) values('1234567890');
SQL> insert into t2(v1) values('12345678901');
SQL> insert into t2(v1) values('123456789012');
SQL> insert into t2(v1) values('123456789012345678');
SQL> insert into t2(v1) values('1234567890123456789');
SQL> insert into t2(v1) values('12345678901234567890');
SQL> insert into t2(v1) values('123456789012345678901');
SQL> insert into t2(v1) values('12345678901234567890123');
SQL> insert into t2(v1) values('1234567890123456789012345678');
SQL> insert into t2(v1) values('123456789012345678901234567890');
SQL> insert into t2(v1) values('1234567890123456789012345678901');
Statement failed, SQLSTATE = 22001
arithmetic exception, numeric overflow, or string truncation
-string right truncation
SQL>
Це працює в 2.5, у 3.0 поводиться інакше з utf8
SQL> create table t2(v1 varchar(10) character set UNICODE_FSS);
SQL> insert into t2(v1) values('12345678901');
SQL> insert into t2(v1) values('12345678901234567890');
SQL> insert into t2(v1) values('12345678901234567890123456789');
SQL> insert into t2(v1) values('123456789012345678901234567890');
SQL> insert into t2(v1) values('1234567890123456789012345678901');
Statement failed, SQLSTATE = 22001
arithmetic exception, numeric overflow, or string truncation
-string right truncation
-expected length 10, actual 30
SQL> create table t3(v1 varchar(10) character set utf8);
SQL> insert into t3(v1) values('1234567890');
SQL> insert into t3(v1) values('12345678901');
Statement failed, SQLSTATE = 22001
arithmetic exception, numeric overflow, or string truncation
-string right truncation
-expected length 10, actual 11
SQL>