Calculating string length in a model

I'm using Ruby 2.1.1 and Rails 4.1.1, with SQLite and, respectively,
Postgres.

All my strings are supposed to be UTF-8 encoded.

Now, assuming I create a field in my model as

   data:string{20}

can I safely assume, that this will store up to 20 characters, even if
each character happens to be 3 bytes long in UTF-8 encoding?

From the Postgres docs (http://www.postgresql.org/docs/9.3/static/datatype-character.html):

“SQL defines two primary character types: character varying(n) and character(n), where n is a positive integer. Both of these types can store strings up to n characters (not bytes) in length.”

So that sounds like yes. :slight_smile:

–Matt Jones