A string of text using Rails 3.2. * and Postgres - should I always use text

I adopted a Rails application (Rails 3.2 and Postgres 9.4) that has a few Rails lines and we passed the 255 limit. This application previously used MySQL and not Postgres as its backing store. I understand that postgres treats lines and text the same way. It's right? Are there any restrictions we need to be aware of before wrapping all our Rails lines into texts?

Performance issues are an issue, but not a major issue.

+3


source to share


1 answer


From the exact guide :

Council . There is no performance difference between the three types, other than the increased storage space when using the empty type and a few extra CPU cycles to check the length while maintaining the length -configured column. While it character(n)

has performance advantages in some other database systems, PostgreSQL does not; in fact, character(n)

it is usually the slowest of the three due to its additional storage costs. In most cases, text

or should be used character varying

.

The three types they talk about are char(n)

, varchar(n)

and text

. The council essentially says that:



  • char(n)

    is the slowest due to empty padding and the need to check the length limit.
  • varchar(n)

    usually in the middle because length limitation needs to be checked.
  • text

    (AKA varchar

    without n

    ) is usually the fastest as there is no additional overhead.

Apart from the space for char(n)

and the length checks for char(n)

and varchar(n)

, they are all handled the same behind the scenes.

In ActiveRecord t.string

has varchar

and t.text

is text

. Unless you have hard length limits on your strings, just use t.text

with PostgreSQL.

+6


source







All Articles