Can I store int in longtext column and sum it?

When save a post, I saved a "point" value in post_content_filtered column in wp_posts table. I didn't save it in postmeta table because it's not easy to make sum in postmeta. Also, wordpress never use the post_content_field column for anything. So, I think I'm making good use of it. Now, when I need to sum the "points" for some posts, how to make mysql treat the points as int ?

Answers


I'm not sure if I understand the question but if you have a text field that you would like to treat as an signed integer something like this would work:

SELECT SUM(CAST(post_content_filtered AS SIGNED)) total FROM wp_posts;

I don't think the above will be necassary since mysql will use the field as a number depending on context, for example the following will return 6:

SELECT '1' + '10' - '5';

Read more about mysql cast functions


Need Your Help

Design patterns for multiple language website?

design-patterns localization web internationalization spoken-language

Lets say I'm designing a website where we have English, French, Spanish, German, and Korea (I'm not, but lets pretend I am).

Conditionally activate "acts_on_list" when field is defined

ruby-on-rails acts-as-list

I have a model "entry" and I need it to act like a list when a playlist_id is specified, but if it's not, I need it to not act like a list. (acts_as_list is a gem I'm using)