String column -> Text, 255 limit?

70 views
Skip to first unread message

John Hinnegan

unread,
Aug 17, 2011, 6:32:12 PM8/17/11
to rubyonra...@googlegroups.com
So I'm using a column in my database to serialize a hash of extra data about an object.  Stuff I'd want when displaying, but not anything else I care to have structured access to in my DB.  I recently started storing an URL in field, so I decided I'd better change the column type from string (which it probably should never have been) to text.  

I did so with a standard migration

def self.up
change_column :my_table, :related_data, :text 
end 

Looking in my schema.db file, I see:

   t.text     "related_data",         :limit => 255

I think I know how to fix it, but want some reinforcement I'm on the right track before I spend the time.  Looks like what I really need is:

def self.up
  add_column :my_table, :new_related_data, :text
  # copy data from related_data to new_related_data
  remove_column :my_table, :related_data
  rename_column :my_table, :new_related_data, :related_data
end 

yes?

Philip Hallstrom

unread,
Aug 17, 2011, 7:38:24 PM8/17/11
to rubyonra...@googlegroups.com

Or just...

change_column :my_table, :related_data, :text, :limit => 123456789 # or whatever you think is large enough

-philip

John Hinnegan

unread,
Aug 17, 2011, 7:45:58 PM8/17/11
to rubyonra...@googlegroups.com
That would be easier for sure.  I was just guessing that the limit param was put in because the db was just changing the type on the column, not actually changing the size allocated to the column per record.

Rob Biedenharn

unread,
Aug 18, 2011, 11:40:55 AM8/18/11
to rubyonra...@googlegroups.com


I think that the limit can be 2048 as I recall that is the max for a
URL. I can't find a reference to back that up at the moment, but I
think that this is what the sitemap specification (see Google) allows,
too.

-Rob

Rob Biedenharn
R...@AgileConsultingLLC.com http://AgileConsultingLLC.com/
r...@GaslightSoftware.com http://GaslightSoftware.com/

Philip Hallstrom

unread,
Aug 19, 2011, 12:35:37 PM8/19/11
to rubyonra...@googlegroups.com
>>> So I'm using a column in my database to serialize a hash of extra data about an object. Stuff I'd want when displaying, but not anything else I care to have structured access to in my DB. I recently started storing an URL in field, so I decided I'd better change the column type from string (which it probably should never have been) to text.
>>>
>>> I did so with a standard migration
>>>
>>> def self.up
>>> change_column :my_table, :related_data, :text
>>> end
>>>
>>> Looking in my schema.db file, I see:
>>>
>>> t.text "related_data", :limit => 255
>>>
>>> I think I know how to fix it, but want some reinforcement I'm on the right track before I spend the time. Looks like what I really need is:
>>>
>>> def self.up
>>> add_column :my_table, :new_related_data, :text
>>> # copy data from related_data to new_related_data
>>> remove_column :my_table, :related_data
>>> rename_column :my_table, :new_related_data, :related_data
>>> end
>>>
>>> yes?
>>
>> Or just...
>>
>> change_column :my_table, :related_data, :text, :limit => 123456789 # or whatever you think is large enough
>>
>> -philip
>
>
> I think that the limit can be 2048 as I recall that is the max for a URL. I can't find a reference to back that up at the moment, but I think that this is what the sitemap specification (see Google) allows, too.

http://support.microsoft.com/kb/q208427/

Relevant portion.....

Microsoft Internet Explorer has a maximum uniform resource locator (URL) length of 2,083 characters. Internet Explorer also has a maximum path length of 2,048 characters. This limit applies to both POST request and GET request URLs.

If you are using the GET method, you are limited to a maximum of 2,048 characters, minus the number of characters in the actual path.

However, the POST method is not limited by the size of the URL for submitting name/value pairs. These pairs are transferred in the header and not in the URL.

Michael Pavling

unread,
Aug 20, 2011, 4:32:48 AM8/20/11
to rubyonra...@googlegroups.com
On 19 August 2011 17:35, Philip Hallstrom <phi...@pjkh.com> wrote:
>> I think that the limit can be 2048 as I recall that is the max for a URL.  I can't find a reference to back that up at the moment, but I think that this is what the sitemap specification (see Google) allows, too.
>
> http://support.microsoft.com/kb/q208427/
>
> Relevant portion.....
>
> Microsoft Internet Explorer has a maximum uniform resource locator (URL) length of 2,083 characters. Internet Explorer also has a maximum path length of 2,048 characters. This limit applies to both POST request and GET request URLs.

That's the current limit for IE - but IE is not the internet.

If you check section 3.2.1 of the HTTP RFC, it states:
"The HTTP protocol does not place any a priori limit on the length of
a URI." and also notes that "Servers should be cautious about
depending on URI lengths above 255 bytes, because some older client or
proxy implementations may not properly support these lengths"

So essentially the limit is whatever combination of current clients
can send, and your server can handle. Over time, I'd assume it will
get longer, as more http clients support longer URIs, and more people
rely on them in their apps.

Michael Pavling

unread,
Aug 20, 2011, 4:35:12 AM8/20/11
to rubyonra...@googlegroups.com
On 20 August 2011 09:32, Michael Pavling <pav...@gmail.com> wrote:
> If you check section 3.2.1 of the HTTP RFC, it states:

It would've been polite to include the link! :-)

http://www.faqs.org/rfcs/rfc2068.html

Reply all
Reply to author
Forward
0 new messages