[wp-trac] [WordPress Trac] #27272: WP meta queries comparing apples to oranges

WordPress Trac noreply at wordpress.org
Mon Oct 20 00:23:18 UTC 2014


#27272: WP meta queries comparing apples to oranges
------------------------------------------+-----------------------------
 Reporter:  Denis-de-Bernardy             |       Owner:
     Type:  defect (bug)                  |      Status:  new
 Priority:  normal                        |   Milestone:  Future Release
Component:  Query                         |     Version:  3.8.1
 Severity:  normal                        |  Resolution:
 Keywords:  needs-patch needs-unit-tests  |     Focuses:
------------------------------------------+-----------------------------
Changes (by boonebgorges):

 * keywords:  needs-patch needs-unit-tests 4.0-early => needs-patch needs-
     unit-tests


Comment:

 What is it that we're trying to accomplish with the casting? MySQL does
 some somewhat intelligent type juggling based on the operators you use
 https://dev.mysql.com/doc/refman/5.0/en/type-conversion.html. So the kind
 of example Denis-de-Bernardy describes here
 https://core.trac.wordpress.org/ticket/27272#comment:6 is actually already
 supported. (See [attachment:27272.patch].) As for things like date, my
 tests suggest that as long as you're passing the proper 'type' param for
 casting the 'meta_value' column, MySQL will automatically convert the type
 of your comparison value. So `CAST('2012-04-04' AS DATE) > CAST(meta_value
 AS DATE)` is redundant.

 That said, it's possible that I'm missing something. Can we get a unit
 test that demonstrates how the suggested casting makes a difference in
 results?

--
Ticket URL: <https://core.trac.wordpress.org/ticket/27272#comment:11>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list