Forum: Ruby on Rails Calculating string length in a model

0fa73332c8e4a3b06ea439fd3f034322?d=identicon&s=25 Ronald Fischer (rovf)
on 2014-06-11 14:01
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?
6883e5ef03484d4fcef507d7b4f1d243?d=identicon&s=25 Matt Jones (Guest)
on 2014-06-12 15:14
(Received via mailing list)
On Wednesday, 11 June 2014 07:02:17 UTC-5, Ruby-Forum.com User wrote:
> 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...

"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. :)

--Matt Jones
Please log in before posting. Registration is free and takes only a minute.
Existing account

NEW: Do you have a Google/GoogleMail, Yahoo or Facebook account? No registration required!
Log in with Google account | Log in with Yahoo account | Log in with Facebook account
No account? Register here.