String column -> Text, 255 limit?

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

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.

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
Rob@AgileConsultingLLC.com http://AgileConsultingLLC.com/
rab@GaslightSoftware.com http://GaslightSoftware.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.

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.

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

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