SQLite Forum

length function for BLOB out of sync with documentation
Login
You would have to give an example of what you mean by "constraint on a TEXT column specifies a length value", because there is no way in SQLite3 to do that.

Unless of course you mean a CHECK constraint such as:

```
create table x
(
  x text not null check (typeof(x) == 'text' and length(x) <= 15)
);
```

which would check that the value stored in x is indeed text and that it's length (in characters) is less than or equal to 15.

Simply having something like:

```
create table x
(
 x text not null check (length(x) <= 15)
);
```

would require that any particular value stored in x has a length less than or equal to 15 (characters if what is stored is text, bytes if what is stored is a blob, and a string representation less than 15 characters long if an integer or real value).

If you always want to know "bytes" then you would have to specify that, as in:

```
create table x
(
  x text not null check (length(cast(x as blob)) <= 15)
);
```

which would check that whatever is stored in x is less than or equal to 15 bytes long.  If x was text and the database encoding was utf16, then this would be a max of 7 characters.