[wp-trac] [WordPress Trac] #23033: Decimal and numeric options in meta_query do not produce correct MYSQL for floating point numbers comparisons

WordPress Trac noreply at wordpress.org
Mon Jan 14 07:42:38 UTC 2013


#23033: Decimal and numeric options in meta_query do not produce correct MYSQL for
floating point numbers comparisons
--------------------------+-----------------------------
 Reporter:  ericlewis     |       Owner:  wonderboymusic
     Type:  defect (bug)  |      Status:  accepted
 Priority:  normal        |   Milestone:  3.6
Component:  Query         |     Version:
 Severity:  normal        |  Resolution:
 Keywords:  needs-patch   |
--------------------------+-----------------------------
Changes (by wonderboymusic):

 * keywords:   => needs-patch
 * owner:   => wonderboymusic
 * status:  new => accepted
 * milestone:  Awaiting Review => 3.6


Comment:

 Our support for CAST needs work. Here is what you have to do:

 {{{
 $stuff = new WP_Query( array(
         'meta_query' => array(
                 array(
                         'key' => '_edit_last',
                         'type' => 'decimal',
                         'compare' => '=',
                         'value' => '10.5'
                 )
         )
 ) );

 echo $stuff->request;
 // SELECT SQL_CALC_FOUND_ROWS  wp_posts.ID FROM wp_posts
 // INNER JOIN wp_postmeta ON (wp_posts.ID = wp_postmeta.post_id) WHERE 1=1
 AND wp_posts.post_type = 'post'
 // AND (wp_posts.post_status = 'publish' OR wp_posts.post_status =
 'private') AND
 // ( (wp_postmeta.meta_key = '_edit_last' AND CAST(wp_postmeta.meta_value
 AS DECIMAL) = '10.5') )
 // GROUP BY wp_posts.ID ORDER BY wp_posts.post_date DESC
 exit();
 }}}

 We should probably be casting the value (10.5) so the query doesn't end up
 = (string) '10.5'. We should also support FLOAT.

-- 
Ticket URL: <http://core.trac.wordpress.org/ticket/23033#comment:2>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software


More information about the wp-trac mailing list