Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Force max length for string in PostgreSQL

I am using heroku for a RoR application and am trying to manually set the length of a string column and am having trouble.

I tried making a migration along the lines of

change_column :posts, :content, :string, :length => 10000 

I assumed this would work but no such luck, anyone have some pointers?

Thanks!

like image 648
Jimmy Avatar asked Jun 06 '10 01:06

Jimmy


People also ask

What is the maximum varchar length in Postgres?

What is PostgreSQL Varchar datatype? In PostgreSQL, the Varchar data type is used to keep the character of infinite length. And it can hold a string with a maximum length of 65,535 bytes.

What is maximum length of character varying Postgres?

The maximum limit of size character using character varying data type in PostgreSQL is 10485760. The below example shows that the size of the character using character varying data type in PostgreSQL is 10485760.

What is char [] in PostgreSQL?

The notations varchar( n ) and char( n ) are aliases for character varying( n ) and character( n ) , respectively. character without length specifier is equivalent to character(1) . If character varying is used without length specifier, the type accepts strings of any size. The latter is a PostgreSQL extension.


1 Answers

The length limit option in Rails migrations is called :limit:

change_column :posts, :content, :string, :limit => 10000 

If you are finding yourself changing VARCHAR length limits a lot, you might want to read @depesz's blog post on VARCHAR vs TEXT.

like image 153
Jason Weathered Avatar answered Oct 01 '22 04:10

Jason Weathered