character varying fields on postgresql

331 views
Skip to first unread message

cevado

unread,
Jun 23, 2017, 11:04:36 AM6/23/17
to elixir-ecto
Reading Ecto documentation on migration, more precisely the options for add, https://hexdocs.pm/ecto/Ecto.Migration.html#add/3 it says:
  • :size - the size of the type (for example the numbers of characters). Default is no size, except for :string that defaults to 255.

Tip: There is no performance difference among these three types, apart from increased storage space when using the blank-padded type, and a few extra CPU cycles to check the length when storing into a length-constrained column. While character(n) has performance advantages in some other database systems, there is no such advantage in PostgreSQL; in fact character(n) is usually the slowest of the three because of its additional storage costs. In most situations text or character varying should be used instead.

 
As I understand it, the recomended way to use it is a varchar without size limitation. But the way Ecto works that's not possible, since size default is 255, if i create a migration without specifying a size, it will be character varying(255). Shouln't the default be a character varying without size limitation or at least Ecto could have a atom specifying to dont use size for the field, something like size: :no_limit?

Michał Muskała

unread,
Jun 23, 2017, 1:33:00 PM6/23/17
to elixir-ecto
This behaviour is to align the postgresql adapter with other databases. You can use the text type for unlimited length - they are otherwise equivalent.

Michał.
--
You received this message because you are subscribed to the Google Groups "elixir-ecto" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elixir-ecto...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elixir-ecto/9518f707-46f5-4dd8-8211-9d62298335d3%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages